Repository navigation
feat(gc): add opt-in GC statistics behind a gc-stats feature - #5613
Open
tarushmohindru wants to merge 4 commits into
Open
tarushmohindru wants to merge 4 commits into
tarushmohindru wants to merge 4 commits into
Conversation
Add a `gc-stats` Cargo feature to `boa_gc` (forwarded by `boa_engine`) that records per-thread collector statistics: - collection count, and how many collections also ran the finalize and second mark phases - cumulative bytes and objects allocated and freed - time spent in each collection phase (trace_non_roots, mark, finalize, remark, sweep, weak map pruning) and in total They are exposed through `boa_gc::stats()`, which returns a `GcStats` snapshot, and `boa_gc::reset_stats()`. Byte counts are shallow: only the size of each `GcBox`/`EphemeronBox` is counted. The existing `bytes_allocated` accounting and the collection threshold are unchanged. All new code is behind the feature, which is off by default, so builds without it are unchanged and `Instant::now()` is never compiled for wasm32-unknown-unknown. Part of boa-dev#5567.
Add a `gc-stats` feature to `boa_cli` that forwards to `boa_gc/gc-stats` and exposes the collector statistics on the debug object. `$boa.gc.stats()` returns a plain object with counters and per-phase timings in milliseconds; `$boa.gc.resetStats()` clears them. Part of boa-dev#5567.
Test262 conformance changes
Tested main commit: |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5613 +/- ##
===========================================
+ Coverage 47.24% 63.09% +15.85%
===========================================
Files 476 536 +60
Lines 46892 60553 +13661
===========================================
+ Hits 22154 38208 +16054
+ Misses 24738 22345 -2393 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
jasonwilliams
approved these changes
Nov 9, 2026
jasonwilliams
left a comment
Member
There was a problem hiding this comment.
Sorry this took a while to look at
LGTM
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This Pull Request is a part of #5567.
It changes the following:
gc-statsfeature toboa_gc, forwarded byboa_engineandboa_cli. It is off by default and gates all new code.BoaGc: collections, collections that ran finalize + second mark, cumulative bytes/objects allocated and freed, and wall time per collection phase plus total.boa_gc::stats() -> GcStats(aCopysnapshot) andboa_gc::reset_stats().$boa.gc.stats()and$boa.gc.resetStats()to the CLI debug object.core/gc/src/test/stats.rs.Design notes
gc-statsthe collector is unchanged.std::time::Instant::now()panics onwasm32-unknown-unknown, so timing has to stay opt-in.GcRuntimeData. Stats live in their ownstats: GcStatsfield onBoaGc, soreset_stats()can't touchbytes_allocatedor the collection threshold.runtime.collectionsis left as is (tests rely on it), andGcStats::collectionsis a separate counter that resets.size_of_valof eachGcBox/EphemeronBoxis counted, matching the existingbytes_allocated. Heap memory owned by values (e.g. aVec's buffer) and the boxes backingWeakMaps are not counted. This is documented onGcStats.sweep. Bytes and objects freed are computed frombytes_allocatedand the heap lengths before and after the sweep, so the unsafe code is unchanged.timed!macro that expands to the plain expression when the feature is off, which keepscollect()readable.GcStatsis#[non_exhaustive]so more counters can be added later without a breaking change.Overhead
Release
boa_clibuilt with and without--features gc-stats; V8 Richards and Splay frombenches/scripts/v8-benches, 10 runs each, alternating builds. AMD Ryzen 5 5600H, WSL2, based on9871775a. Higher is better; median with range.Both differences are within code-layout noise: Splay is faster with stats enabled, and Richards performs zero collections and about 8k allocations in total, so the counters can't account for a 1.3% change. Happy for someone with a quieter setup to re-run these.
Example: Splay
With
--features gc-stats --debug-object, printing$boa.gc.stats()after the run:This lines up with the perf estimate in #5567 (~36% of samples), and gives a direct data point for the Phase 1
NEEDS_FINALIZEdiscussion: every collection on Splay paid for finalize and a second full mark.Testing
cargo test -p boa_gcandcargo test -p boa_gc --features gc-statscargo clippy --all-targetsforboa_gcandboa_cli, with and without the feature