Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.3k
events: optimize adding and removing of listeners more#785
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
This keeps in line with how things are done for the fast path and *might* even provide a *slight* performance increase.
evanlucas commented Feb 10, 2015
It seems to offer a significant improvement to more than just ee-add-remove. The ee-listener-count and ee-listeners-many seem to vary a little bit though. |
mscdex commented Feb 10, 2015
Huh... I thought I checked the other benchmarks also... |
mscdex commented Feb 10, 2015
@evanlucas You must be testing against a version of iojs that is pre-b677b844fc1. I tested relative to the current head of v1.x and ee-add-remove is the only one that really shows an improvement. |
evanlucas commented Feb 10, 2015
Ah, I had thought for some reason I was up to date on v1.x. Perhaps not. :] |
Fishrock123 commented Feb 10, 2015
|
mscdex commented Feb 10, 2015
@Fishrock123 Yeah |
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.
Should this be io.js instead of node now?
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.
shrug I didn't change anything in that whole block, just wrapped it all within an else{}.
39599f9 to 9763ffcComparemscdex commented Feb 11, 2015
Code updated with suggested changes. |
lib/events.js Outdated
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 can be made a little flatter and more readable by swapping the consequent and the alternate. Suggestion:
if(events)doError=(type==='error'&&events.error!=null);elseif(type==='error')doError=true;elsereturnfalse;You can condense it but I'll leave it up to you to decide what's more readable.
doError=(type==='error');if(events)doError=(doError&&events.error==null);elseif(!doError)returnfalse;These optimizations result in >2x speedup in the ee-add-remove benchmark: * Don't mutate array.length when removing the last listener for an event * Don't bother checking max listeners if listeners isn't an array * Don't call delete when removing the last event in _events, just re-assign a new object instead
9763ffc to a29f3d3Comparemscdex commented Feb 11, 2015
Updated again with suggested changes. |
bnoordhuis commented Feb 11, 2015
This keeps in line with how things are done for the fast path and *might* even provide a *slight* performance increase. PR-URL: #785 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Evan Lucas <[email protected]>
These optimizations result in >2x speedup in the ee-add-remove benchmark: * Don't mutate array.length when removing the last listener for an event * Don't bother checking max listeners if listeners isn't an array * Don't call delete when removing the last event in _events, just re-assign a new object instead PR-URL: #785 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Evan Lucas <[email protected]>
bnoordhuis commented Feb 11, 2015
Thanks Brian, landed in 630f636...7061669. |
ChALkeR commented May 25, 2015
// This is a brutally ugly hack to make sure that our error handler// is attached before any userland ones. NEVER DO THIS.if(!dest._events||!dest._events.error)dest.on('error',onerror);elseif(Array.isArray(dest._events.error))dest._events.error.unshift(onerror);elsedest._events.error=[onerror,dest._events.error];Edit: Sorry, I was wrong, it's fine =). |
These optimizations result in >2x speedup in the ee-add-remove
benchmark:
an event
re-assign a new object instead