-
-
Notifications
You must be signed in to change notification settings - Fork 161
perf(regex): construction skips the write barrier's parent classification #9891
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
Closed
proggeramlug
wants to merge
2
commits into
PerryTS:main
from
proggeramlug:perf/regex-newborn-barrier-gate
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,43 @@ | ||
| **A `RegExp` literal's construction no longer pays the write barrier's parent | ||
| classification.** Since #9845 the `RegExpHeader` is a nursery allocation, so | ||
| its two string field stores — `pattern_ptr` and `flags_ptr` — cannot owe the | ||
| remembered set anything; they were still taking the full barrier and | ||
| discovering that fact, twice, at a cost of four page-map classifications, two | ||
| dirty-page-cache probes and two child classifications per construction, all | ||
| ending at `ParentNotOldSkips`. | ||
|
|
||
| The fix is the runtime twin of a gate the compiler already emits in front of | ||
| every one of its own stores (`emit_parent_may_need_remembering_check`, #7511): | ||
| `GC_FLAG_TENURED` clear on the parent's live header **and** a globally idle | ||
| incremental mark barrier ⇒ neither the remembered set nor the SATB shading has | ||
| anything to record. Both clauses are read live, so a header a collection | ||
| promoted between `arena_alloc_gc` and the store, or a | ||
| `RegExp.prototype.compile` reassigning a tenured receiver, still takes the | ||
| full path. | ||
|
|
||
| Why the two clauses and not one: the tenured bit answers the generational | ||
| question, and the incremental count is what makes it legal to skip the | ||
| insertion shading as well — dropping either is a live child swept, which is | ||
| what `gc::tests::inline_generation_gate_contract` already pins for the emitted | ||
| gate and now pins for the runtime twin, clause by clause, against the same | ||
| codegen predicate. A third test asserts on the header `js_regexp_new` actually | ||
| returns, so the skip arm is proven reached rather than merely available. | ||
|
|
||
| Measured motivation (segment-loop probe, region B, 60,000 reps, `sample`, main | ||
| thread, leaf sum = thread header exactly): the probe constructs one `RegExp` | ||
| per grapheme from a literal inside a function body, and the barrier subtree | ||
| under `js_regexp_new` is 739 of 14,628 main-thread samples — 32 % of that | ||
| function's own subtree. | ||
|
|
||
| `PERRY_REGEX_NEWBORN_BARRIER_GATE=0` restores the unconditional pair; with the | ||
| gate off nothing else changes, so the OFF arm is the pre-change code path | ||
| exactly rather than a handicapped control. | ||
|
|
||
| `PERRY_REGEX_DIAG` gains the counters that make the claim checkable rather | ||
| than argued: `barrier_taken` / `barrier_gated` (whose sum must equal `new`), | ||
| `header_bytes`, `site_verify_bytes` (the site cache's byte-compare volume, | ||
| which `pattern_bytes` does not isolate) and `side_table_inserts`. Two | ||
| reliability fixes ride along: a diag file the process cannot write now says so | ||
| on stderr and falls back there instead of vanishing silently, and the first | ||
| snapshot is written at the first tick rather than after a full second, so a | ||
| short run can no longer look like a dead instrument. |
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
Emit the initial snapshot on the first event, or narrow the release-note claim.
last_dump = Noneonly makes the dump due when the existing 256-event tick occurs. A process with 1–255regex_withcalls still writes no snapshot.crates/perry-runtime/src/hot_diag.rs#L191-L194: emit the initial snapshot before theTICK_EVERYthreshold if immediate output is required.changelog.d/9885-regex-newborn-barrier-gate.md#L40-L43: if the 256-event threshold remains intentional, state that the first eligible tick emits immediately instead of claiming all short runs produce output.📍 Affects 2 files
crates/perry-runtime/src/hot_diag.rs#L191-L194(this comment)changelog.d/9885-regex-newborn-barrier-gate.md#L40-L43🤖 Prompt for AI Agents