Skip to content

src: cache trace category lookups on hot paths - #67502

Open
gurgunday wants to merge 1 commit into
nodejs:mainfrom
gurgunday:perf/trace-category-cache
Open

gurgunday wants to merge 1 commit into
nodejs:mainfrom
gurgunday:perf/trace-category-cache

Conversation

@gurgunday

Copy link
Copy Markdown
Member

The sync fs, fs dir, AsyncWrap and vm.Script tracing guards call TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED directly, which does a by-name search in the tracing controller on every call

Use TRACE_EVENT_CATEGORY_ENABLED instead, which caches the category pointer per call site like the other TRACE_EVENT macros. Perfetto already provides it, so add an equivalent for the legacy tracing build

benchmark/compare.js, 30 runs:

benchmark configuration improvement
fs/bench-statSync.js fstatSync +9.28 % ***
lstatSync +8.71 % ***
statSync +6.82 % ***
fs/bench-existsSync.js existing +12.36 % ***
non-existing +12.26 % ***
non-flat-existing +9.37 % ***
fs/bench-accessSync.js accessSync existing +9.44 % ***
accessSync non-existing +3.23 %
accessSync non-flat-existing +9.48 % ***
fs/bench-statSync-failure.js noThrow lstatSync +12.49 % ***
noThrow statSync +8.41 % ***
throw fstatSync +8.93 % ***
throw lstatSync +1.64 %
throw statSync +2.67 %

fs/bench-openSync.js, fs/bench-opendirSync.js and the async fs/bench-stat.js are within noise.

The sync fs, fs dir, AsyncWrap and vm.Script tracing guards called
TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED directly, which does a
by-name search in the tracing controller on every call. Use
TRACE_EVENT_CATEGORY_ENABLED instead, which caches the category
pointer per call site like the other TRACE_EVENT macros. Perfetto
already provides it; add an equivalent for the legacy tracing build.

Assisted-by: claude:opus-5.5
Signed-off-by: Gürgün Dayıoğlu <hey@gurgun.day>
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run. labels Nov 15, 2026
@codecov

codecov Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.66%. Comparing base (55da353) to head (5da6baf).
⚠️ Report is 15 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67502      +/-   ##
==========================================
- Coverage   90.66%   90.66%   -0.01%     
==========================================
  Files         799      799              
  Lines      280245   280242       -3     
  Branches    54121    54123       +2     
==========================================
- Hits       254097   254094       -3     
  Misses      16277    16277              
  Partials     9871     9871              
Files with missing lines Coverage Δ
src/async_wrap.cc 83.28% <100.00%> (ø)
src/node_contextify.cc 81.59% <100.00%> (-0.02%) ⬇️
src/node_dir.cc 70.76% <ø> (ø)
src/node_file.cc 75.92% <ø> (-0.09%) ⬇️

... and 26 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.

@gurgunday gurgunday added author ready PRs with CI started, the required approvals, and no outstanding review comments. request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. labels Nov 16, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 16, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

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

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants