lib: cache length prop in classic for loop#34217
Conversation
Cache length prop in classic for loop for performance purpose. Refs: nodejs#30958
It appears that the CI failed to clone cc @himself65 |
Yes, I see. restart new one |
|
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. |
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. |
|
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. |
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. |
|
@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 |
|
@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. |
|
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