-
-
Notifications
You must be signed in to change notification settings - Fork 164
perf(gc): survival-aware nursery pacing, 4 MB floor on the existing influx ladder (includes #11612) #11645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
perf(gc): survival-aware nursery pacing, 4 MB floor on the existing influx ladder (includes #11612) #11645
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
aa957d8
perf(regex): stop charging operation scratch to GC external pressure;…
proggeramlug 5ee0156
changelog: #11612 regex scratch is not GC pressure
proggeramlug e720e0d
perf(gc): survival-aware nursery pacing: the ladder starts at a quart…
perry-bot d6bcdbe
chore(gc): classify the external-side byte counters in the root-holde…
perry-bot 356e189
changelog: #11645 survival-aware nursery pacing
perry-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| perf(regex): regex operation scratch is no longer reported to the collector as external side bytes (#11549). The owned search path's per-call match buffers, compile scratch, KMP tables and replacer argument slots are freed by the operation and bounded by its `MemoryBudget`, but each release fed `GC_EXTERNAL_SIDE_DRAINED_SINCE_FULL` and paced loops over >32-register programs (dotenv's `LINE`) into a full mark-sweep every few hundred calls. The lent per-thread scratch cell now grows its registers on demand up to 1024 (8 KiB per thread), so such programs stop building per-call buffers. Subject-proportional replace storage is still reported. Instructions: dotenv/parse −30.1%, moment/parse_format −13.8%, validator/batch −1.9%; peak RSS rises on moment/parse_format (+29%) because those loops now pace by the 16 MB nursery like other allocating programs — held pending the young-generation pacing half of #11549. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - **gc: survival-aware nursery pacing (Part of #11549).** The scavenge nursery cap's influx ladder now starts at a quarter of the 16 MB base (4 MB). It climbs toward the unchanged 64 MB top only while survivor influx stays above 4% of the cap. A ladder move takes every step the one-step rule would take on the same reading, so survivor-heavy programs settle where they used to, two minors in. The survivor target, the promoted-cohort floor and the census seed point stay on the 16 MB base. Measured against main `7fa094cb4` with THP off: dotenv −30.5% instructions and −20.3% peak RSS; moment −20.6% instructions; validator −26.0% RSS; date-fns −30.0% RSS; jsonwebtoken −22.0% RSS; uuid −21.0% RSS; gc_ratchet 01 −25.5% RSS. **Owner-accepted trade, 2026-09-30, tracked in #11699** (re-measured on main `034b1ea38`, with #11676): a program that holds a large live structure and exits after 4–16 MB of allocation now runs a minor that main never ran (binary-trees n=3/6/10: +498/+433/+369% instructions, +60/+55/+49% RSS); gc_ratchet 02 is +19.8% instructions, 12_large_live_set +2.5% RSS, moment +13.8% RSS (an unexplained shift that #11699 tracks), qs parse +0.75% instructions, and the allocation loop +0.57%. Also classifies `GC_EXTERNAL_SIDE_*` as byte counters in `scripts/gc_runtime_root_holders.json`, because #11612's commits turned that gate red. |
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
140 changes: 140 additions & 0 deletions
140
crates/perry-runtime/src/gc/tests/runtime_roots/perex_scratch_pressure.rs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| //! #11549: a regex operation's own scratch is not collector pressure. | ||
| //! | ||
| //! Operation scratch (`perex_memory::Buffer`, the owned search path's match | ||
| //! buffers, the lent cell) is freed by the operation, never by a collection. | ||
| //! Reporting it as external side bytes put every per-call buffer's release into | ||
| //! `GC_EXTERNAL_SIDE_DRAINED_SINCE_FULL`, which old-reclaim holds as pressure | ||
| //! until the next full: dotenv's `LINE` (42 registers, past the lent cell's old | ||
| //! fixed 32) ran a budgeted full mark-sweep every ~250 parses on phantom bytes. | ||
| use super::*; | ||
| use crate::gc::policy::{external_side_live_bytes, GC_EXTERNAL_SIDE_DRAINED_SINCE_FULL}; | ||
| use crate::regex::perex_api as api; | ||
| use crate::regex::perex_memory::{Buffer, MemoryBudget}; | ||
| use crate::regex::perex_runtime::{EngineError, OWNED_SEARCHES}; | ||
| use crate::regex::RegExpHeader; | ||
| use crate::string::StringHeader; | ||
|
|
||
| fn text<'s>(scope: &'s RuntimeHandleScope, bytes: &[u8]) -> RuntimeHandle<'s> { | ||
| scope.root_string_ptr(crate::string::js_string_from_bytes( | ||
| bytes.as_ptr(), | ||
| bytes.len() as u32, | ||
| )) | ||
| } | ||
|
|
||
| fn regex<'s>(scope: &'s RuntimeHandleScope, pattern: &str) -> RuntimeHandle<'s> { | ||
| let pattern = text(scope, pattern.as_bytes()); | ||
| let flags = text(scope, b""); | ||
| scope.root_raw_mut_ptr(pattern.with_const_ptr::<StringHeader, _>(|pattern| { | ||
| flags.with_const_ptr::<StringHeader, _>(|flags| crate::regex::js_regexp_new(pattern, flags)) | ||
| })) | ||
| } | ||
|
|
||
| fn search( | ||
| re: &RuntimeHandle<'_>, | ||
| input: &RuntimeHandle<'_>, | ||
| ) -> Result<Option<(usize, usize)>, EngineError> { | ||
| re.with_mut_ptr::<RegExpHeader, _>(|re| { | ||
| input.with_const_ptr::<StringHeader, _>(|input| { | ||
| api::execute(re, input, false, &mut || Ok(())) | ||
| .map(|found| found.map(|m| (m.full.start(), m.full.end()))) | ||
| }) | ||
| }) | ||
| } | ||
|
|
||
| /// `groups` capturing groups of one `a` each: `(a)(a)...`. A program's register | ||
| /// count is at least twice its capture count (group zero included), so this | ||
| /// needs at least `2 * (groups + 1)` registers. | ||
| fn groups_pattern(groups: usize) -> String { | ||
| "(a)".repeat(groups) | ||
| } | ||
|
|
||
| fn external_readings() -> (usize, usize) { | ||
| ( | ||
| external_side_live_bytes(), | ||
| GC_EXTERNAL_SIDE_DRAINED_SINCE_FULL.with(TriggerInput::get), | ||
| ) | ||
| } | ||
|
|
||
| fn owned_searches() -> usize { | ||
| OWNED_SEARCHES.with(std::cell::Cell::get) | ||
| } | ||
|
|
||
| #[test] | ||
| fn perex_operation_buffer_is_not_reported_as_external_side_bytes() { | ||
| let _guard = CopyingNurseryTestGuard::new(0); | ||
| let _triggers = GcTriggerThresholdTestGuard::suppress_automatic_triggers(); | ||
| let before = external_readings(); | ||
| let memory = MemoryBudget::new(1 << 20); | ||
| { | ||
| let buffer = Buffer::<usize>::new(&memory, 4096).expect("fits the budget"); | ||
| assert_eq!(buffer.len(), 4096); | ||
| assert_eq!(memory.live_bytes(), 4096 * 8, "the budget still sees it"); | ||
| assert_eq!(external_readings(), before, "allocation noted nothing"); | ||
| } | ||
| assert_eq!(memory.live_bytes(), 0); | ||
| assert_eq!(memory.peak_bytes(), 4096 * 8); | ||
| assert_eq!( | ||
| external_readings(), | ||
| before, | ||
| "a released operation buffer is not drained external pressure (#11549)" | ||
| ); | ||
| // The budget remains the bound: past it, nothing is allocated. | ||
| assert!(Buffer::<usize>::new(&memory, (1 << 20) / 8 + 1).is_err()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn perex_search_past_32_registers_uses_the_lent_cell_and_notes_nothing() { | ||
| let _guard = CopyingNurseryTestGuard::new(0); | ||
| let _triggers = GcTriggerThresholdTestGuard::suppress_automatic_triggers(); | ||
| super::perex_public::register_host_roots(); | ||
| let scope = RuntimeHandleScope::new(); | ||
| // 20 groups: 42+ registers, which the lent cell's old fixed 32 could not | ||
| // hold, so every call built and dropped owned match buffers. | ||
| let re = regex(&scope, &groups_pattern(20)); | ||
| let input = text(&scope, "a".repeat(25).as_bytes()); | ||
| // The first call may grow the thread's cell; every later one must not | ||
| // build anything. | ||
| assert_eq!(search(&re, &input).unwrap(), Some((0, 20))); | ||
| let before = external_readings(); | ||
| let owned = owned_searches(); | ||
| for _ in 0..64 { | ||
| assert_eq!(search(&re, &input).unwrap(), Some((0, 20))); | ||
| } | ||
| assert_eq!( | ||
| owned_searches(), | ||
| owned, | ||
| "a program within the lent bound searches on the lent cell" | ||
| ); | ||
| assert_eq!( | ||
| external_readings(), | ||
| before, | ||
| "and reports no scratch to the collector" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn perex_search_past_the_lent_bound_takes_the_owned_path_and_notes_nothing() { | ||
| let _guard = CopyingNurseryTestGuard::new(0); | ||
| let _triggers = GcTriggerThresholdTestGuard::suppress_automatic_triggers(); | ||
| super::perex_public::register_host_roots(); | ||
| let scope = RuntimeHandleScope::new(); | ||
| // 600 groups: 1,202+ registers, past what the lent cell may retain. The | ||
| // cell must not grow to it; the operation builds, and frees, its own. | ||
| let re = regex(&scope, &groups_pattern(600)); | ||
| let input = text(&scope, "a".repeat(600).as_bytes()); | ||
| let before = external_readings(); | ||
| let owned = owned_searches(); | ||
| for _ in 0..4 { | ||
| assert_eq!(search(&re, &input).unwrap(), Some((0, 600))); | ||
| } | ||
| assert_eq!( | ||
| owned_searches(), | ||
| owned + 4, | ||
| "a program past the lent bound runs the owned path every call" | ||
| ); | ||
| assert_eq!( | ||
| external_readings(), | ||
| before, | ||
| "owned match buffers are released by the search, not drained into GC pressure" | ||
| ); | ||
| } | ||
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Use the target’s
usizesize in budget assertions.On 32-bit targets,
usizeoccupies four bytes, not eight. (doc.rust-lang.org) The live and peak assertions therefore fail. The allocation at Line 82 also fits the budget instead of exceeding it.Use
std::mem::size_of::<usize>()in all three expressions.Proposed fix
Also applies to: 75-75, 82-82
🤖 Prompt for AI Agents