Repository navigation
feat(ts): place a loop's exit after it - #85
Conversation
Quest-Claim: 9e877970a736eb96
…while 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 696eae4d209f3b21b1c0847ccba6e8e6a0823427 against base 87344d54dcdfe16062d1a57fd229540196cb3b67.
No actionable bugs found. Checked natural-loop membership and exit placement, nested/multiple exits, exit nodes that also head loops, label adoption/removal, switch-sensitive breaks, and the changed generated fixtures.
Direction: Keeping normal test exits after the loop while leaving other exits inline is a focused improvement. The final AST cleanup preserves the existing structurer and avoids adding coroutine/runtime machinery for the remaining size gap. The reported alternatives and measurements justify that scope; I found no clearly simpler equivalent that needs to block this change.
Verification: GitHub-only static review; I did not run tests, type-checks, or benchmarks or independently reproduce the size/timing claims. The head's Check workflow was still running at review time.
(Written by OpenAI)
Problem
ts-mir-size continued after #79: the codec was 1.3% over THIR's gzip and the handoff 38% minified and 8.6% gzipped. MIR's structurer placed a loop's exit inside the loop, nesting the rest of the function in the branch that leaves (
while (true) { if (!(c)) { ...rest...; return; } ... }), where THIR hadfor/whileloops with the rest after them.Approach
cfg::Shape, a node that the loop's test leaves to (the header, and the nodes one way in and one way on after it, up to its first branch) is placed after the loop and reached bybreak. Other ways out, often areturnor?from within, stay inline, where they are shorter.cfg::tidy_loops), after the passes that match labeled jumps: a loop takes the label of a block that holds only it,while (true) { if (c) break; .. }becomeswhile (!c) { .. }(andif (c) { a } else break;becomeswhile (c) { a .. }), and a jump to the innermost loop it is in drops its label.orderednow readswhile ((_15 = iterStart++) < iterEnd) { .. } let sum = 0; ..rather than four nested loops.The quest stays, rewritten with what is left and why.
Impact
Output shape only. Behavior is unchanged:
just ts testcompares every fixture against native Rust, andjust ts moqstill type-checks.Size
Placing every exit after its loop, not only the test's, left the codec 23 bytes larger minified than this: an early
returnturns into abreakplus thereturnafter the loop.Speed
Two
just ts benchruns with main as--route, alternating with the A/A control: the geometric mean of this PR ÷ main, and A/A ÷ main for the noise. The host was loaded by other agents (load average 17-33 on 32 threads), so Node's and Bun's handoff are noise.Chrome's codec gap in run 1 came from
btree/16andbtree/256(1.25, A/A 1.01) and thetime/u64pair (1.24-1.29, A/A 0.81-0.90); in run 2 those were 0.82/1.63 and 0.84/0.86.btreeisordered, the function this reshapes most, so it was timed alone: 8 alternating Chrome processes per minified bundle, this PR ÷ main at 16/256/4096 keys is 0.64/0.82/0.87 against A/A 0.95/0.96/0.77; Node 1.00/0.90/1.01 (A/A 1.05/0.96/1.02), Bun 0.98/0.98/0.89 (A/A 1.03/1.02/0.93). No loss shows above the noise.Alternatives
catch, each class keeping its ownresumeso its calls stay monomorphic. 792 bytes smaller minified, 38 larger gzipped, so not timed. A base can't read a subclass's private#state, so only those two pieces can move.#state = 2on entry, so a cleanup that only poisons needs nocatcharm): about size-neutral on a one-await class, since the write lands in each resumed arm.async fnthat only awaits anotherasync fnof its arguments: exact, and it would erase the 16levelNclasses, but it removes the depth the handoff measures and moq-net's wrappers awaitkio::wait, which it can't collapse.Follow-ups
The quest stays, rewritten: the handoff's minified gap is the fixture's 16
levelNclasses (about 360 bytes each against 135 for THIR's generator), while its gzip gap (284 bytes with one level each) is outside them, indrainFuture's dispatch,recvFuture, and the steppedforloops ofregisterandwake.just ts benchtimes unminified bundles, while the quest asks for minified timings; making the bench time what it measures for size could be its own quest.(written by Opus 5.5)
🤖 Generated with Claude Code
https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn