-
-
Notifications
You must be signed in to change notification settings - Fork 158
perf(codegen): admit forwarded arrays in versioned loops #8767
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
Closed
Changes from all commits
Commits
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
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
108 changes: 108 additions & 0 deletions
108
crates/perry/tests/versioned_indexed_loop_forwarding.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,108 @@ | ||
| //! Runtime regression for forwarded arrays in fallback-free checked-reader | ||
| //! loops. Array growth preserves JavaScript identity by leaving a forwarding | ||
| //! stub behind; loop admission must normalize one edge to the live array, and | ||
| //! a later callback-driven growth must still side-exit before the next effect. | ||
|
|
||
| use std::path::PathBuf; | ||
| use std::process::{Command, Output}; | ||
|
|
||
| fn perry_bin() -> PathBuf { | ||
| PathBuf::from(env!("CARGO_BIN_EXE_perry")) | ||
| } | ||
|
|
||
| fn run_fixture(binary: &std::path::Path, force_evacuation: bool) -> Output { | ||
| let mut command = Command::new(binary); | ||
| if force_evacuation { | ||
| command.env("PERRY_GC_FORCE_EVACUATE", "1"); | ||
| } else { | ||
| command.env_remove("PERRY_GC_FORCE_EVACUATE"); | ||
| } | ||
| command | ||
| .output() | ||
| .expect("run versioned indexed-loop fixture") | ||
| } | ||
|
|
||
| #[test] | ||
| fn forwarded_arrays_enter_safely_and_callback_growth_resumes_generically() { | ||
| let dir = tempfile::tempdir().expect("tempdir"); | ||
| let entry = dir.path().join("main.ts"); | ||
| let binary = dir.path().join("main_bin"); | ||
| std::fs::write( | ||
| &entry, | ||
| r#" | ||
| class Reader { | ||
| entities: number[] = []; | ||
|
|
||
| private checkedRead(column: any[] | undefined, index: number, type: number): any { | ||
| if (column === undefined) throw new Error("missing column " + type); | ||
| const value = column[index]; | ||
| if (value === 99) throw new Error("missing value " + type + " at " + index); | ||
| return value; | ||
| } | ||
|
|
||
| iterate( | ||
| column: any[], | ||
| callback: (entity: number, value: any) => void, | ||
| entityFilter?: (entity: number) => boolean, | ||
| ): void { | ||
| const entities = this.entities; | ||
| const entityCount = entities.length; | ||
| const cb = callback; | ||
| for (let i = 0; i < entityCount; i++) { | ||
| const entity = entities[i]!; | ||
| if (entityFilter && !entityFilter(entity)) continue; | ||
| cb(entity, this.checkedRead(column, i, 1)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const reader = new Reader(); | ||
| const column: any[] = []; | ||
| for (let i = 0; i < 4096; i++) { | ||
| reader.entities.push(i); | ||
| column.push({ n: i }); | ||
| } | ||
|
|
||
| let sum = 0; | ||
| let grew = false; | ||
| reader.iterate(column, (entity, value) => { | ||
| sum += entity + value.n; | ||
| if (!grew) { | ||
| grew = true; | ||
| for (let i = 0; i < 4096; i++) column.push({ n: -1 }); | ||
| } | ||
| }, undefined); | ||
|
|
||
| console.log(sum + ":" + reader.entities.length + ":" + column.length); | ||
| "#, | ||
| ) | ||
| .expect("write versioned indexed-loop fixture"); | ||
|
|
||
| let compile = Command::new(perry_bin()) | ||
| .current_dir(dir.path()) | ||
| .arg("compile") | ||
| .arg(&entry) | ||
| .arg("-o") | ||
| .arg(&binary) | ||
| .arg("--no-cache") | ||
| .arg("--no-auto-optimize") | ||
| .output() | ||
| .expect("compile versioned indexed-loop fixture"); | ||
| assert!( | ||
| compile.status.success(), | ||
| "compile failed\nstdout:\n{}\nstderr:\n{}", | ||
| String::from_utf8_lossy(&compile.stdout), | ||
| String::from_utf8_lossy(&compile.stderr) | ||
| ); | ||
|
|
||
| for force_evacuation in [false, true] { | ||
| let run = run_fixture(&binary, force_evacuation); | ||
| assert!( | ||
| run.status.success(), | ||
| "fixture failed (force_evacuation={force_evacuation})\nstdout:\n{}\nstderr:\n{}", | ||
| String::from_utf8_lossy(&run.stdout), | ||
| String::from_utf8_lossy(&run.stderr) | ||
| ); | ||
| assert_eq!(String::from_utf8_lossy(&run.stdout), "16773120:4096:8192\n"); | ||
| } | ||
| } | ||
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
Clear inherited collector configuration before running the fixture.
run_fixtureonly controlsPERRY_GC_FORCE_EVACUATE. If the parent process sets another collector variable, such asPERRY_GEN_GC=0orPERRY_GC_MOVING_SAFEPOINT=0, the forced-evacuation arm can pass without exercising relocation.Remove all inherited Perry collector-knob variables before setting the intended value for this test arm.
Proposed fix
fn run_fixture(binary: &std::path::Path, force_evacuation: bool) -> Output { let mut command = Command::new(binary); + for name in [ + "PERRY_GEN_GC", + "PERRY_GEN_GC_EVACUATE", + "PERRY_GC_SCAVENGE", + "PERRY_GC_SCAVENGE_NURSERY_MB", + "PERRY_GC_MOVING_SAFEPOINT", + "PERRY_GC_MOVING_LOOP_POLLS", + "PERRY_GC_FORCE_EVACUATE", + "PERRY_CONSERVATIVE_STACK_SCAN", + "PERRY_WRITE_BARRIERS", + "PERRY_GC_INCREMENTAL", + "PERRY_GC_HEAP_LIMIT", + ] { + command.env_remove(name); + } if force_evacuation { command.env("PERRY_GC_FORCE_EVACUATE", "1"); - } else { - command.env_remove("PERRY_GC_FORCE_EVACUATE"); }Based on learnings: remove inherited Perry collector-knob environment variables before applying the test arm’s intended environment.
📝 Committable suggestion
🤖 Prompt for AI Agents
Source: Learnings