Skip to content

Comments

Faster array map and forEach#3399

Merged
josdejong merged 6 commits intodevelopfrom
faster-array-map-and-forEach
Feb 27, 2025
Merged

Faster array map and forEach#3399
josdejong merged 6 commits intodevelopfrom
faster-array-map-and-forEach

Conversation

@dvd101x
Copy link
Collaborator

@dvd101x dvd101x commented Feb 21, 2025

Hi,

This is a way to increase performance of map and forEach when iterating over arrays. The main improvement in speed is by cloning the index only for the callback. Includes an argument called skip index that avoids the costly iteration over an index.

Implements a naive skip zeros in collection.

Unknown-4

@josdejong
Copy link
Owner

That looks great 😎 . I'll review the code next week, it looks good at first sight.

@dvd101x
Copy link
Collaborator Author

dvd101x commented Feb 25, 2025

Later on I want to try using for loops, instead of array.map and array.forEach. Similar to #3395

Would you recommend doing it here or testing afterwards in a different PR to compare performance?

@dvd101x
Copy link
Collaborator Author

dvd101x commented Feb 26, 2025

The change to for had a noticeable improvement so I included it in this PR.

Unknown

@josdejong
Copy link
Owner

Very nice! Good idea to utilize the knowledge about not needing to provide the index in the callback!

@josdejong josdejong merged commit cf4e419 into develop Feb 27, 2025
15 checks passed
@josdejong josdejong deleted the faster-array-map-and-forEach branch February 27, 2025 12:28
@josdejong
Copy link
Owner

Published now in v14.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants