-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Optimize the Ref
class in src/core/primitives.js
#10394
Optimize the Ref
class in src/core/primitives.js
#10394
Conversation
The `toString` method always creates two string objects (for the 'R' character and for the `num` concatenation) and in the worst case creates three string objects (one more for the `gen` concatenation). For the Tracemonkey paper alone, this resulted in 12000 string objects when scrolling from the top to the bottom of the document. Since this is a hot function, it's worth minimizing the number of string objects, especially for large documents, to reduce peak memory usage. This commit refactors the `toString` method to always create only one string object.
/botio-linux preview |
From: Bot.io (Linux m4)ReceivedCommand cmd_preview from @timvandermeij received. Current queue size: 0 Live output at: http://54.67.70.0:8877/c118ee9c7f3f1c6/output.txt |
From: Bot.io (Linux m4)SuccessFull output at http://54.67.70.0:8877/c118ee9c7f3f1c6/output.txt Total script time: 1.64 mins Published |
/botio test |
From: Bot.io (Linux m4)ReceivedCommand cmd_test from @timvandermeij received. Current queue size: 0 Live output at: http://54.67.70.0:8877/6e131889aa9b018/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_test from @timvandermeij received. Current queue size: 0 Live output at: http://54.215.176.217:8877/713a6c149745dab/output.txt |
From: Bot.io (Linux m4)SuccessFull output at http://54.67.70.0:8877/6e131889aa9b018/output.txt Total script time: 17.74 mins
|
From: Bot.io (Windows)SuccessFull output at http://54.215.176.217:8877/713a6c149745dab/output.txt Total script time: 23.28 mins
|
Thank you for the review, @Snuffleupagus! |
The
toString
method always creates two string objects (for the 'R' character and for thenum
concatenation) and in the worst case creates three string objects (one more for thegen
concatenation). For the Tracemonkey paper alone, this resulted in 12000 string objects when scrolling from the top to the bottom of the document. Since this is a hot function, it's worth minimizing the number of string objects, especially for large documents, to reduce peak memory usage.This commit refactors the
toString
method to always create only one string object.