Repository navigation
feat(ts): smaller output from MIR - #95
Conversation
Quest-Claim: 4f881bb5b70f75e4
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
A bundle with only 64-bit sums, like the async handoff's u64Add, no longer pulls in the 128-bit limbs. sum64 reads halves without boxing a number into limbs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
for-of over an array took Firefox 1.19x as long on the async handoff against the stepped loop (A/A 1.05), and Chrome no less time. Without it the handoff is 3440 bytes gzipped, under its 3458 target. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
The Firefox gap was the bench's first translated route, not for-of: timed the other way round, the stepped loops were the slow ones by the same margin, and each A/A copy matched the other build. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: ee97a90
No actionable bugs found in the temporary-folding evaluation-order guards, narrowly matched array-loop rewrite, coroutine field sharing, or width-specific sum helpers. Direction looks sound: using rustc's storage-conflict information and splitting the runtime by width are simpler than broader liveness analysis or bundler-dependent specialization. Keeping the remaining codec-size gap explicit is appropriate.
The new optimizer rules would benefit from focused negative regression cases (lazy reads, mutation/panic ordering, and overlapping saved locals), beyond regenerated snapshots. Verification: source and generated-snapshot inspection only; I did not run the translator, differential tests, or benchmarks, and have not independently verified the reported size/speed results.
…ff2db0c3036 # Conflicts: # ts/fixtures/lang/expected/shapes.ts
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Each case fails the lang differential when its rule in inline::folds is removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: 829e4d2
No actionable bugs found in the substantive update since my previous review (accounting for the main merge). The new shapes.rs regression cases address the earlier mutation/panic-ordering coverage suggestion: the snapshot retains the pre-mutation read and evaluates division before the potentially overflowing addition. Direction is good—focused differential fixtures add coverage without expanding optimizer complexity; the remaining size gap is now documented against the newer baseline.
Verification: inspected the added Rust cases, generated TypeScript, harness reachability and relevant folding guards. I did not run tests or benchmarks, and have not independently verified the revised size measurements.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 829e4d2c47
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| && reads.reads.get(&upvar) == Some(&1) | ||
| { | ||
| moved.insert(layout.variant_fields[variant][field], upvar.index()); |
There was a problem hiding this comment.
Keep repeatedly copied captures separate from saved locals
For an async move block that copies a capture inside a loop, one syntactic read does not mean the capture is read only once during execution. For example, async move { let mut total = 0; for _ in 0..2 { let mut x = n; x += 1; std::future::ready(()).await; total += x; } total } produces a saved-local assignment from the captured n that satisfies this predicate. Aliasing x with the capture makes x += 1 overwrite n, so the next iteration starts from the modified value: with n = 5, the result becomes 13 instead of native Rust's 12. Exclude these repeated copies unless their safety is proven, and add a differential case covering the loop.
AGENTS.md reference: AGENTS.md:L15-L15
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed, and reproduced. A looped case in blocks copies a capture inside a while loop with an await, and it differed from native Rust in 351 task cases.
Fixed in 44f089d. The copy now keeps the upvar's field only if both of these hold:
- It runs at most once. It is not reachable from a later poll's resume target, and not from itself.
- Nothing the first poll runs before the copy, or instead of it, uses the local.
Removing both run-once checks brings the 351 differences back. The handoff's argument fields still qualify, so the sizes are unchanged.
(written by Opus 5.5)
|
Re the review, I broke each guard on purpose to see whether a test catches it:
(written by Opus 5.5) |
A capture copied into a local on each pass of a loop shared the capture's field, so changing the copy changed what the next pass copied. The copy must now run at most once, in the first poll, before any other use of the local there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
…ff2db0c3036 # Conflicts: # ts/fixtures/codec/expected/coding/version.Versions.ts # ts/fixtures/lang/expected/keys.ts # ts/fixtures/lang/expected/shapes.ts
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: e873acd
The independent P1 capture-aliasing finding, missed in my earlier review, is addressed in the inspected code: field reuse now excludes copies reachable from later polls or a cycle, and requires the copy to precede other saved-local uses. The added loop regression keeps base and x separate in generated TypeScript.
No new actionable bugs found in this update after accounting for upstream merges. Direction is sound: conservative reachability checks are justified here and avoid a broader alias analysis. Verification was source/CFG reasoning and snapshot inspection only; I did not run tests or independently verify the reported mutation-test results.
…ff2db0c3036 # Conflicts: # ts/fixtures/codec/expected/bench.ts # ts/fixtures/codec/expected/coding/decode.Decoder.ts # ts/fixtures/codec/expected/coding/encode.Encoder.ts # ts/fixtures/codec/expected/coding/varint.ts # ts/fixtures/codec/expected/harness.ts # ts/fixtures/lang/expected/chars.ts # ts/fixtures/lang/expected/collections.ts # ts/fixtures/lang/expected/fmt.ts # ts/fixtures/lang/expected/ints.ts # ts/fixtures/lang/expected/iters.ts # ts/fixtures/lang/expected/keys.ts # ts/fixtures/lang/expected/shapes.ts # ts/fixtures/lang/src/shapes.rs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Claims quest/m2/ts-mir-size.md.
Problem
The MIR lowering's bundles are larger than THIR's. On main (80f4487), the async handoff is 3720 bytes gzipped against a 3458 target. The codec is 31347 minified and 10063 gzipped, against 30629 and 9422.
Approach
Four cuts. Each one keeps Chrome's speed.
inline.rs): aconstread once moves into the next statement's first evaluated expression. It only moves when nothing between the two could observe the move, meaning no write, panic, or memory read on either side.step::for_of): this matchesregisterandwake'swhile (true) { const x = i < s.length ? s[i++] : DONE; if (x === DONE) break; ... }.storage_conflicts).this.#x = this.#xis dropped.rt/int.tsgetssum64andsum128in place of onesumthat took the width. The handoff's only wide op isu64Add. Its overflow path used to pull in the 128-bit limbs, which a bundler can't shake out of a shared function.Sizes, minified / gzipped:
On the main before #87, the cuts measured one at a time were as follows (handoff gzipped):
sum64/sum128: 3363. The codec also went from 9733 to 9651.Only the handoff's goal is met. The codec misses both of its goals.
The codec's gap came from PRs that landed after THIR's numbers were taken, not from the lowering:
rt/int.ts. Before feat(ts): drop what std types hold, by glue and droppers #87, THIR's own output bundled with this PR'srt/int.tswas 31112 / 9666. That is over MIR's 30094 / 9651 at the same point.rt.ByteSliceadded 580 / 156.The quest now covers only the codec's remainder.
Timing
quest gateruns ofjust ts bench --route main=<main's translation>. Each cell is the geomean of PR/main, with A/A/main and the A/A spread (median and max over workloads) in brackets.Against main at 80f4487, the head (host load average 10-13):
Against main at #91, the head before #82 (quieter, load 8-10):
Chrome shows no loss beyond the A/A spread. The codec sits at 1.01-1.02, with the A/A median spread at 3-7%. Two earlier pairs, on the main before #87, gave Chrome codec 1.009-1.014 and handoff 0.94-0.96.
Firefox's handoff 1.08-1.18 is the bench, not this PR. In every Firefox run, the
translatedroute is 10-17% slower than its own A/A copy, an identical build. To check for-of, I timed the PR with and without it in both directions:Whichever build is
translatedlooks slow by the same margin, and each A/A copy matches the other build.Impact
rt/int.tschanges only private helpers, and its exports are the same.lang'sindexedgains two cases. In the first, a value is read before a call that changes it and used after that call. In the second, two operands can each panic. Removing the write rule or the panic rule frominline::foldsfails thelangdifferential.task'sblocksgains a capture copied into a local on each pass of a loop. Without the run-once checks, 351 cases differ from native Rust.sum64's carry failscodecandlang.just checkandjust testpass.Alternatives
unwindstores, and merging identical cleanup arms. They are listed in the quest and left out.Follow-ups
just ts benchtimes the firsttranslatedroute 10-17% slower than its A/A copy in Firefox's handoff. This hides real changes of that size. It is suggested for/quest-plan, not filed.(written by Opus 5.5)
🤖 Generated with Claude Code
https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn