-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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: add type check for event name #31428
Conversation
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.
Will this be semver-minor or semver-major for the possible breaking changes on existing codes? |
CITGM: https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/2238/ (queued) |
This comment has been minimized.
This comment has been minimized.
/ping @nodejs/tsc This is a straightforward change, but it is semver-major so will need TSC reviews. |
This needs to be thoroughly benchmarked before it can land. This is one of the single most performance sensitive apis in core. |
I’m +1 if it does not cause a perf regression to the eventemitter, http, and streams benchmarks. |
3f532fa
to
950c12c
Compare
rebased/squashed and updated commit message |
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.
Is there any risk of breaking existing code? If so, would a deprecation cycle be better?
Benchmark run (may take a while for the link to be good while jenkins spins up the job): https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/514/ |
Results of the benchmark run:
The significant slow down in |
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.
Making -1 explicit until benchmark results can be looked at.
According to docs only string/symbol are allowed but the checks done are more relaxed and allow additionally number/bigint as it seems they are used in user land modules.
7cd7155
to
d301636
Compare
Seems using an if instead a switch is significant faster. |
I'll kick off another CI benchmark run to double check :-) |
@jasnell Seems you accidentally started benchmarks for category assert instead event |
Sigh lol ok. Will restart soon |
new benchmark results:
|
Still a bit of a concern. It's interesting that the ee-add-remove shows a significant regression in the second run but not the first. I think that's just really showing the performance sensitivity in this part. I guess I can't really come up with a great argument not to add this but I'm also not really seeing much of a benefit to adding this check. @addaleax and @mcollina, what do you think? |
I’m personally good with not adding typechecking if it affects performance – for events, it wouldn’t be a need-to-have anyway (and I’ve never seen non-string/symbol values being passed as event names in the wild, too). |
According to docs only
string
/symbol
are allowed but the checks are more relaxed to allow alsonumber
/bigint
as it seems they are used in user land modules.There were already checks in place in the past and they have been removed have been removed.
Another try to add them again was done but never finished (#21007).
Therefore I'm not sure if this should be added or not. As I had most of the changes already in place once I noticed this I think it's better to discuss this in a PR.
Fixes: #31331
Refs: 0468861
Refs: #21007
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesEdit: Removed
null
as it was removed during review phase.