Uh oh!
There was an error while loading. Please reload this page.
lib: avoid using Array.prototype.forEach - #11582
Conversation
richardlau
commented
Feb 27, 2017
How many forEach's are left? Is it worth having a lint rule to catch? |
bmeurer
commented
Feb 27, 2017
We are aware of this, and work on the Array builtins (forEach, filter, and friends) already started. |
jasnell
commented
Feb 27, 2017
@richardlau ... only a handful but they are either a bit more complicated to refactor or are otherwise not in code that is that performance critical. At this point I don't believe a lint rule is required. @bmeurer ... yeah, I figured as much :-) It's a significant enough of a gap right now that making this change makes sense. I've separated each changed file into a separate commit so that we can selectively roll back as necessary once performance improvements are made :-) |
I am guessing https://bugs.chromium.org/p/v8/issues/detail?id=5269 is the related tracking issue? Just linking stuff :). EDIT: or maybe this: https://bugs.chromium.org/p/v8/issues/detail?id=1956 |
jasnell
commented
Feb 27, 2017
There was a problem hiding this comment.
I think just 'for' would be more descriptive since they are both iterating over an array.
jasnell
commented
Feb 27, 2017
@mscdex ... I renamed the |
bmeurer
commented
Feb 28, 2017
Relevant upstream bugs are https://bugs.chromium.org/p/v8/issues/detail?id=1956 and https://bugs.chromium.org/p/v8/issues/detail?id=2229. Full parity with for-of/for vs. forEach requires shipping TurboFan for all JS first, so probably V8 5.9 or 6.0 can provide the performance. |
JacksonTian
commented
Feb 28, 2017
Some forEach not in critical path. |
I've always been in favor of replacing all instances of |
jasnell
commented
Mar 4, 2017
Ping @nodejs/collaborators |
There was a problem hiding this comment.
I'm curious why ...args is being used when we're just using it with .apply() which should handle arguments just fine.
There was a problem hiding this comment.
Either way works for me really
There was a problem hiding this comment.
I would vote for changing to using arguments while we're in here.
There was a problem hiding this comment.
Perhaps these could be named a bit clearer, like makeDeprecateGetter() or maybe makeDepGetter(), and similarly with makeSetter().
cjihrig
left a comment
There was a problem hiding this comment.
LGTM. Tiniest nit: would you mind using i as the loop variable instead of n. We aren't consistent, but i seems to be used more.
There was a problem hiding this comment.
This doesn't use j at all. Wouldn't this be optimized away?
There was a problem hiding this comment.
Can we drop writable? By default it is false
thefourtheye
commented
Mar 5, 2017
Hope none of the changes here involve sparse arrays. That would change the semantics of the loop iteration. |
jasnell
commented
Mar 6, 2017
None of the loops appear to involve sparse arrays that I can see. |
jasnell
commented
Mar 6, 2017
@thefourtheye ... updated to address your feedback. PTAL |
jasnell
commented
Mar 15, 2017
ping @thefourtheye |
thefourtheye
left a comment
There was a problem hiding this comment.
Sorry for the delay. Belated LGTM.
PR-URL: nodejs#11582 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: nodejs#11582 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: nodejs#11582 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: nodejs#11582 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: nodejs#11582 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: nodejs#11582 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: nodejs#11582 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: nodejs#11582 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: nodejs#11582 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: nodejs#11582 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: nodejs#11582 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: nodejs#11582 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: nodejs#11582 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: nodejs#11582 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: nodejs#11582 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: nodejs#11582 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: nodejs#11582 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: nodejs#11582 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: nodejs#11582 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
PR-URL: nodejs#11582 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
italoacasas
commented
Mar 21, 2017
@jasnell this PR need backport to v7 |
MylesBorins
commented
Apr 17, 2017
+1 for v6.x backport |
Using
Array.prototype.forEach()is still significantly slower than traditional array iteration. This PR adds a benchmark and replaces many (but not all)forEach()uses within lib.Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
lib