-
Notifications
You must be signed in to change notification settings - Fork 7
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
add/remove handlers are slow on EventTarget #60
Comments
During adding a event listener we traverse the entire linkedlist to find duplicates, i tried to avoid that here nodejs/node@f6c2580 but it seems not much of a perf improvement, almost same performance, any other methods in mind? |
Given maps support iterating in insertion order iirc - what about using maps instead of linked lists and not just for duplicate checking? |
Unless I'm missing something, using Maps and calling |
So the implementation of |
@metcoder95 makes sense let me see making the change |
Tried this not really any improvement 😅 confidence improvement accuracy (*) (**) (***)
events/eventtarget.js listeners=1 n=1000000 0.74 % ±4.06% ±5.41% ±7.04%
events/eventtarget.js listeners=10 n=1000000 1.59 % ±4.39% ±5.84% ±7.61%
events/eventtarget.js listeners=5 n=1000000 -1.41 % ±4.27% ±5.70% ±7.47%
events/eventtarget.js listeners=50 n=1000000 1.34 % ±4.03% ±5.38% ±7.05%
Be aware that when doing many comparisons the risk of a false-positive result increases.
In this case, there are 4 comparisons, you can thus expect the following amount of false-positive results:
0.20 false positives, when considering a 5% risk acceptance (*, **, ***),
0.04 false positives, when considering a 1% risk acceptance (**, ***),
0.00 false positives, when considering a 0.1% risk acceptance (***) |
Also I think this would need a fresh benchmark? this given benchmark is primarily measuring speed of event dispatch it could look something like for (let i = 0; i < n; i++) {
const list = [];
for (let j = 0; j < listeners; j++) {
const fn = () => {}
target.addEventListener('foo', fn);
list.push(fn);
}
// remove the listeners from list....
} |
That's sad 🙁
Maybe splitting it into two biggest chunks? add/remove, and event dispatch? |
Trying to open a new pr with this add and remove benchmark |
Opened and PR and as (probably expected) my code shows significant regression 😕 with this benchmark |
Refs: nodejs/performance#60 PR-URL: #46779 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Refs: nodejs/performance#60 PR-URL: #46779 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Refs: nodejs/performance#60 PR-URL: #46779 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Refs: nodejs/performance#60 PR-URL: #46779 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
To the point that e.g. RxJS choose not to implement the abort signal pattern.
ReactiveX/rxjs#6675 (comment)
The text was updated successfully, but these errors were encountered: