Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.2k
lib: cache length prop in classic for loop#34217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
SukkaW commented Jul 6, 2020 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Cache length prop in classic for loop for performance purpose. Refs: nodejs#30958
himself65 commented Jul 6, 2020 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
SukkaW commented Jul 6, 2020
It appears that the CI failed to clone cc @himself65 |
himself65 commented Jul 6, 2020
Yes, I see. restart new one |
mscdex commented Jul 6, 2020
V8 has optimized the existing style (not caching array length) for quite some time now and last I checked/heard caching the length can actually prevent such optimizations from happening. Additionally I would be very surprised if these changes showed up in http benchmarks because other things like network I/O and the http parser are going to dominate the majority of the time spent. |
SukkaW commented Jul 6, 2020 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
As I said, according to my own practices, cache length prop manually is still at least 7% (mostly 15%) faster, and Node.js itself utilize the syntax as well. But I am really curious about benchmark results.
See #30958 (review). All header manipulations and socket operations are considered as performance sensitive. |
mscdex commented Jul 6, 2020
The reason for that is that there was a time when caching the length did improve performance in general, but that was a long time ago. |
SukkaW commented Jul 6, 2020
It is known to all that most modern JavaScript Engines apply optimization in that way. But in most cases, cache In the end, only the benchmark will tell the answer. |
mscdex commented Jul 9, 2020 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
@himself65 I think you'll probably want to stop the I suggest manually selecting the minimal set of files in benchmarks/http (that cover the |
himself65 commented Jul 9, 2020
@mscdex |
This issue/PR was marked as stalled, it will be automatically closed in 30 days. If it should remain open, please leave a comment explaining why it should remain open. |
jasnell commented Oct 28, 2023
Closing due to lack of progress. |
Cache length prop in classic for loop for performance purpose.
Refs: #30958
There is a common view that the modern javascript engine will perform the optimization in
for (;)loop (classic for loop). But according to my own practices, cachelengthprop manually is still at least 7% (mostly 15%) faster.According to #30958 (review), some
for (;)is retained for performance concern, IMHO adding such a "optimization" should be accepted then.FYI, I have noticed that
lib/_http_outgoing.jsalready uses the same syntax when I bring up the PR:node/lib/_http_outgoing.js
Lines 242 to 245 in 30cc542
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes