-
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: use nullish coalencing operator #38328
Conversation
Could use this here instead of checking for all falsy values, a little bit more readable as well.
I think a benchmark that utilizes |
How may I add that? Sorry I've never worked with Node.js benchmarks before. |
Just create a new file in benchmarks/events. You can use one of the existing benchmark files in there as a guide/starting point. |
Created the benchmark for new listeners.
Done, I'm not sure if that's how I'm supposed to do it though. |
Used the increment assignment operator (`+=`) for consistency on all benchmarks.
What I wrote seems to be working perfectly, no idea what else am I supposed to do. |
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.
The basic change LGTM if there's not a significant perf regression. I did not look at the benchmark code.
Added a single event listener instead of 10 and now only exercising the new changes, and fixed random listener property.
@VoltrexMaster There is no need to emit |
By "before the timed loop" do you mean before where the benchmark actually starts? ( |
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.
Thank you for this! Only putting 'request changes' so this doesn't land without benchmarks showing no performance regression. Code looks good otherwise 🙏
Yes. |
@mscdex the "(new) boolean parameter ( |
@VoltrexMaster ee-add-remove would look like this, using the current copy from the master branch (I've also added a parameter for testing 'use strict';
const common = require('../common.js');
const events = require('events');
const bench = common.createBenchmark(main, {
newlistener: [0, 1],
removelistener: [0, 1],
n: [1e6],
});
function main({ newlistener, removelistener, n }) {
const ee = new events.EventEmitter();
const listeners = [];
for (let k = 0; k < 10; k += 1)
listeners.push(() => {});
if (newlistener === 1)
ee.on('newListener', (event, listener) => {});
if (removelistener === 1)
ee.on('removeListener', (event, listener) => {});
bench.start();
for (let i = 0; i < n; i += 1) {
const dummy = (i % 2 === 0) ? 'dummy0' : 'dummy1';
for (let k = listeners.length; --k >= 0; /* empty */) {
ee.on(dummy, listeners[k]);
}
for (let k = listeners.length; --k >= 0; /* empty */) {
ee.removeListener(dummy, listeners[k]);
}
}
bench.end(n);
} |
Oh thanks, I didn't know what those properties on the |
Fixed the `ee-newlistener` benchmark.
CI check failed for timeout, pushing to fix.
Sorry, I meant you can just update the ee-add-remove.js benchmark file instead of creating a new one. |
Oh, how you said it made me think you meant to create a new one with copying and modifying it, Imma delete this one and edit the existing one then 😁 |
Deleted the ee-newlistener benchmark and modified the ee-add-remove benchmark with the changes.
Benchmark CI results seem to look ok, although I'm not sure why the |
¯\_(ツ)_/¯ |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Landed in 6e6663b |
PR-URL: #38328 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]>
PR-URL: #38328 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]>
Could use this here instead of checking for all falsy values, a little bit more readable as well.