Skip to content

v8: avoid truncating cppgc heap statistics - #64696

Open
Archkon wants to merge 1 commit into
nodejs:mainfrom
Archkon:v8gcstat
Open

v8: avoid truncating cppgc heap statistics#64696
Archkon wants to merge 1 commit into
nodejs:mainfrom
Archkon:v8gcstat

Conversation

@Archkon

@Archkon Archkon commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Convert cppgc size_t counters directly to JavaScript Numbers instead of narrowing them to uint32_t.

This prevents v8.getCppHeapStatistics() values from wrapping when a cppgc heap statistic exceeds 4 GiB.

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. v8 engine Issues and PRs related to the V8 dependency. labels Jul 23, 2026
Convert cppgc size_t counters directly to JavaScript Numbers instead
of narrowing them to uint32_t.

This prevents v8.getCppHeapStatistics() values from wrapping when a
cppgc heap statistic exceeds 4 GiB.

Signed-off-by: Archkon <180910180+Archkon@users.noreply.github.com>
@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.13%. Comparing base (0992f6b) to head (85f3230).
⚠️ Report is 243 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #64696      +/-   ##
==========================================
- Coverage   90.14%   90.13%   -0.01%     
==========================================
  Files         741      741              
  Lines      242112   242107       -5     
  Branches    45605    45604       -1     
==========================================
- Hits       218244   218224      -20     
- Misses      15360    15379      +19     
+ Partials     8508     8504       -4     
Files with missing lines Coverage Δ
src/node_v8.cc 88.18% <100.00%> (-0.11%) ⬇️

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

Comment thread src/node_v8.cc
Number::New(isolate,
static_cast<double>(object_stats.allocated_bytes)),
Number::New(isolate,
static_cast<double>(object_stats.object_count))};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should instead optionally be handling these as bigint/uint64_t. Accept the truncation by default, add an option to return bigint instead...

v8.getCppHeapStatistics({ detailLevel: '...', bigint: true });

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joyeecheung ... what do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should instead optionally be handling these as bigint/uint64_t. Accept the truncation by default, add an option to return bigint instead...

v8.getCppHeapStatistics({ detailLevel: '...', bigint: true });

Could you explain a bit more ?I don't completely understand that why we should accept the data that wrap?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should instead optionally be handling these as bigint/uint64_t. Accept the truncation by default, add an option to return bigint instead...

Are any of these realistically in danger of hitting kMaxSafeInteger?

@Archkon

Archkon commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

@joyeecheung Please take look at this

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@Renegade334 Renegade334 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a pure improvement to me, the likelihood of any of these values being exabytes in size seems exceedingly remote, whereas wrapping after a few gigabytes seems like a genuine pitfall.

@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

c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. v8 engine Issues and PRs related to the V8 dependency.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants