events: use nullish coalencing operator#38328
events: use nullish coalencing operator#38328VoltrexKeyva wants to merge 7 commits intonodejs:masterfrom
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. |
jasnell
left a comment
There was a problem hiding this comment.
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? ( |
benjamingr
left a comment
There was a problem hiding this comment.
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 <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com>
PR-URL: #38328 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com>
Could use this here instead of checking for all falsy values, a little bit more readable as well.