-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
lib: refactor join to inline stuff in loop #33854
Conversation
// It is faster not to use a template string here | ||
str += output[i]; | ||
str += separator; | ||
str += (i !== arrayLen - 1) ? separator : ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks costly, which may be shown by a quick benchmark or simply time
-ing this for a large number of iterations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think V8 should do the optimization to inline the stuff and remove comparison as the comparison is already provided. Will do a timing benchmark.
Can we benchmark just getting rid of this? It's been a long time since v8 6.0. |
@devsnek Join string performance check -- array size 1000000
native/join: 5.081699997186661 ms
util/join: 146.29249899089336 ms
Join string performance check -- array size 5
native/join: 16.52709999680519 / 100000
util/join: 9.16829900443554 / 100000 |
@sapics how about if we do a conditional check and use the method based on the length of the array to join.
One interesting thing to note is the performance difference in smaller parts 🤔 |
@yashLadha I think that it is better performance, generally. |
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. |
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes