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.

@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.71%. Comparing base (3e797cb) to head (c42179c).
⚠️ Report is 63 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67502      +/-   ##
==========================================
- Coverage   90.73%   90.71%   -0.03%     
==========================================
  Files         801      801              
  Lines      280710   280709       -1     
  Branches    54178    54174       -4     
==========================================
- Hits       254709   254646      -63     
- Misses      16196    16218      +22     
- Partials     9805     9845      +40     
Files with missing lines Coverage Δ
src/async_wrap.cc 83.28% <100.00%> (ø)
src/node_contextify.cc 81.68% <100.00%> (-0.19%) ⬇️
src/node_dir.cc 70.76% <ø> (ø)
src/node_file.cc 77.03% <ø> (ø)

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

This comment was marked as outdated.

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>
@gurgunday
gurgunday force-pushed the perf/trace-category-cache branch from 5da6baf to c42179c Compare November 18, 2026 08:43
@gurgunday

Copy link
Copy Markdown
Member Author

Fixed the conflict

@jasnell jasnell added 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 18, 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 18, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@gurgunday gurgunday added the resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. label Nov 20, 2026
@github-actions github-actions Bot removed the resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. label Nov 20, 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