-
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
events: optimize listener array cloning #1050
Conversation
This both switches to a single algorithm for array cloning and also speeds up (by ~100% in the ee-listeners-many benchmark) the "many elements" case that was previously handled by `array.slice()`.
return ret; | ||
function arrayClone(arr, i) { | ||
var copy = new Array(i); | ||
while (i--) |
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.
Curious, is iterating backwards faster than forward?
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.
According to this jsperf and this jsperf it appears so, at least in this case.
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.
Yeah, it's really micro, but I also always do this when possible/sane, idk I guess I just like the way it looks. XD
LGTM |
+1, kill all the magic numbers. |
LGTM |
This both switches to a single algorithm for array cloning and also speeds up (by ~100% in the ee-listeners-many benchmark) the "many elements" case that was previously handled by `array.slice()`. PR-URL: #1050 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Julian Duque <julianduquej@gmail.com>
Thanks, landed in 555a7c4. |
This both switches to a single algorithm for array cloning and also
speeds up (by ~100% in the ee-listeners-many benchmark) the
"many elements" case that was previously handled by
array.slice()
.