-
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: improve removeListener() performance #10572
Conversation
var first = array[0];
if (UseSparseVariant(array, len, IS_ARRAY(array), len)) {
SparseMove(array, 0, 1, len, 0);
} else {
SimpleMove(array, 0, 1, len, 0);
}
array.length = len - 1;
return first; And if (UseSparseVariant(array, len, IS_ARRAY(array), changed_elements)) {
%NormalizeElements(array);
if (IS_ARRAY(deleted_elements)) %NormalizeElements(deleted_elements);
SparseSlice(array, start_i, del_count, len, deleted_elements);
SparseMove(array, start_i, del_count, len, num_elements_to_add);
} else {
SimpleSlice(array, start_i, del_count, len, deleted_elements);
SimpleMove(array, start_i, del_count, len, num_elements_to_add);
} We only care about the simple case, so SimpleSlice(array, start_i, del_count, len, deleted_elements);
SimpleMove(array, start_i, del_count, len, num_elements_to_add); Which should be about the same amount of work given the slice does mostly nothing in this case. That said, Anyway - sorry for the storytelling - change LGTM and can confirm the benchmark - just wanted to validate in code. |
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.
LGTM
Previous CI run had some red... running again just to make sure: https://ci.nodejs.org/job/node-test-pull-request/5700/ |
array.shift() seems to be faster than arrayClone() when the item to remove is at the front (at least with V8 5.4). PR-URL: nodejs#10572 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
4142605
to
aab1dd6
Compare
array.shift() seems to be faster than arrayClone() when the item to remove is at the front (at least with V8 5.4). PR-URL: nodejs#10572 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
array.shift() seems to be faster than arrayClone() when the item to remove is at the front (at least with V8 5.4). PR-URL: nodejs#10572 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
array.shift() seems to be faster than arrayClone() when the item to remove is at the front (at least with V8 5.4). PR-URL: nodejs#10572 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
array.shift() seems to be faster than arrayClone() when the item to remove is at the front (at least with V8 5.4). PR-URL: nodejs#10572 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
@mscdex how long should this bake before lts? |
array.shift()
seems to be faster thanarrayClone()
when the item to remove is at the front (at least with V8 5.4).Comparing the results of the events/ee-add-remove.js benchmark shows ~7% improvement:
NOTE: I have not yet tested
array.shift()
performance on V8<5.4, so this may/may not be applicable to node versions prior to 7.0.0.CI: https://ci.nodejs.org/job/node-test-pull-request/5660/
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)