Skip to content

events: use indexed appends in eventNames - #66875

Open
rozzilla wants to merge 1 commit into
nodejs:mainfrom
rozzilla:events-optimize-event-names
Open

rozzilla wants to merge 1 commit into
nodejs:mainfrom
rozzilla:events-optimize-event-names

Conversation

@rozzilla

Copy link
Copy Markdown
Contributor

Use indexed appends when collecting active names in EventEmitter.eventNames(), avoiding a primordial push call per name. Key ordering and filtering of removed listeners remain unchanged.

Local benchmarks on Apple M2/macOS with V8 15.6 show higher throughput:

  • Repeated reads with 32-name fixtures: +9.6-12.6%.
  • Add/read/remove cycles with 32-name fixtures: +8.2-12.0%.
  • Four-name mixed string/symbol add/read/remove cycles: +6.2%.

Across 26 cases and 3,120 samples, seven gains were confirmed in both comparison directions after Holm correction. No corrected-significant regressions were detected, including listener-read and emission controls.

Collect active event names with indexed writes instead of calling
the primordial push function for each name.

Signed-off-by: Roberto Bianchi <roberto.bianchi@spendesk.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/performance

@nodejs-github-bot nodejs-github-bot added events Issues and PRs related to EventEmitter and the events module. needs-ci PRs that need a full CI run. labels Oct 20, 2026
@codecov

codecov Bot commented Oct 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.51%. Comparing base (531d28f) to head (02452d8).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66875      +/-   ##
==========================================
+ Coverage   90.49%   90.51%   +0.01%     
==========================================
  Files         797      797              
  Lines      278221   278252      +31     
  Branches    53462    53468       +6     
==========================================
+ Hits       251786   251857      +71     
+ Misses      16809    16768      -41     
- Partials     9626     9627       +1     
Files with missing lines Coverage Δ
lib/events.js 99.60% <100.00%> (ø)

... and 29 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

events Issues and PRs related to EventEmitter and the events module. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants