Skip to content

perf(codegen): a loop region whose body calls out takes no array it only reads element values from - #11860

Merged
proggeramlug merged 2 commits into
mainfrom
regfix-region-value-reads
Oct 4, 2026
Merged

proggeramlug merged 2 commits into
mainfrom
regfix-region-value-reads

Conversation

@proggeramlug

@proggeramlug proggeramlug commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Fixes the #10594 userplain and #10510 date_getTime regressions that #11790 introduced.

Cause

#11790 (#10741) makes an array a loop-region candidate when it is read at a static index (x & c) in any context. const d = ds[i & 63]; a += d.valueOf() therefore became a region loop over ds. The region was versioned, and the body triplicated (425 to 1,882 IR lines), to save one guarded element load per iteration. The method call in the body sets the region's dirty flag, so every iteration re-checks the guard. Both rows went from 151/158 to 167/176 instructions per op.

Fix

In a body that calls out (a call, new, a native method call), an array becomes a candidate only when the region serves it there: the body stores into it, or a Number consumer takes one of its reads (the dense raw-f64 facts). A call-free body keeps every proven-index read as before. There the facts hold across iterations, and the matrix's varying cells (const o = objs[k & 7]; o.d = k; h += o.a) depend on it. Static-index value reads still ride along once some other access makes the array a candidate.

Results (instructions per op)

row morning main this PR
#10594 userplain 151 167 149
#10510 date_getTime 158 176 158

Real workloads (n=5, median instructions:u; main = 5b06d69)

workload main instr this PR delta full GCs main/PR RSS KB main/PR binary bytes main/PR
tsc (transpile x3) 185,061,848,135 184,882,479,994 -0.10% 247/244 323,232/325,372 182,782,336/182,782,336
zod x5000 19,830,425,976 19,828,116,479 -0.01% 0/0 59,088/59,420 24,440,056/24,440,056
qs parse_nested 32,987,388,575 32,988,301,059 +0.00% 0/0 60,064/60,544 27,301,072/27,301,072
commander parse_argv 8,912,043,876 8,911,944,007 -0.00% 0/0 57,240/57,564 34,203,080/34,203,080

Outputs are identical to main's in every run.

Verification

  • New codegen test an_array_only_read_for_element_values_is_not_a_region_array. Its controls show that a Number-consumed masked read, and a value read in a call-free body, still make the array a region array. All region_array_loop_tests and region_loop_tests pass.
  • perry-codegen (all) passed. Gap suite (1254 files) compared with main: 0 regressions. fmt: clean.
  • Matrix (583 cells), all PRs of this lane combined against main: 3 cells +1..+4 instructions, 36 better. The varying cells are unchanged.

@coderabbitai

coderabbitai Bot commented Oct 4, 2026

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 943f26d4-9563-4144-ae7f-20734b067800
📥 Commits

Reviewing files that changed from the base of the PR and between e9575d8 and 6e21910.

📒 Files selected for processing (3)
  • changelog.d/PENDING-regfix-region-value-reads.md
  • crates/perry-codegen/src/expr/region_array_loop_tests.rs
  • crates/perry-codegen/src/stmt/region_loop/arrays.rs
 ___________________________________________
< Crossing the tensor streams to find bugs. >
 -------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@proggeramlug
proggeramlug merged commit 6235411 into main Oct 4, 2026
31 of 35 checks passed
@proggeramlug
proggeramlug deleted the regfix-region-value-reads branch October 4, 2026 00:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant