Skip to content

perf(ts): leave out runtime the codec's bundle never calls - #119

Merged
kixelated merged 4 commits into
mainfrom
quest/m2/ts-mir-size
Oct 27, 2026
Merged

kixelated merged 4 commits into
mainfrom
quest/m2/ts-mir-size

Conversation

@kixelated

@kixelated kixelated commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

quest/m2/ts-mir-size.md: the codec's bundle on just ts bench was larger than the THIR lowering's (at most 30629 bytes minified and 9422 gzipped). On current main it measured 30722 and 9819. Most of it was runtime code the bundle carried but never called.

Approach

Each cut leaves out runtime the codec never calls; none changes what runs.

cut codec min codec gzip handoff gzip
main 30722 9819 3420
bounds tests "exhausted" in r, not instanceof RangeInclusive, so btreeRange no longer pulls in the whole class 29872 9597 3420
64- and 128-bit shifts, bitwise ops, leading_*, and {from,to}_be_bytes split into a function per width, so a bundle without u128 drops the bigint paths 29476 9473 3423
TryFromIntError a plain object, as the README maps a struct without drop glue 29433 9456 3423
u32/i32::from_be_bytes read one unrolled word, which u64's now shares, not a byte loop 29360 9427 3423
Iter's nextBack and len declared through an interface, not stubbed with a throw 29235 9392 3423

Targets: codec at most 30629 / 9422, handoff at most 3458 gzipped. Both met.

Speed, Chrome 155, --route main=<main's translations> in the same run, translated ÷ main per workload:

run cuts geomean median
1 first three 0.979 0.995
2 first three 0.994 0.998
3 all 1.001 0.998

Each outlier past 10% either way had A/A on the other side (A/A differed from translated by up to 38% in a run). Host: Ryzen 9 5900XT, 32 threads, load average 0.4 to 6.3 during the runs, each run through quest gate.

Choices made without asking:

  • A missing nextBack or len now throws JS's TypeError: ... is not a function instead of the runtime's rust2-ts: an iterator without .... Rust calls either only where std implements the trait, so it was a stub for a translator bug; it still fails loud, with the method's name.
  • word and putWord read and write a 32-bit word unrolled; 64-bit to_be_bytes no longer allocates an array of words.

Impact

  • rt.TryFromIntError is a type, not a class: new rt.TryFromIntError(...) is gone. The translator only ever names it as a type.
  • rt.Iter's nextBack and len are no longer inherited stubs; subclasses that implement them are unchanged.
  • No change to the translator or its output.
  • Consumer: moq, whose translated bundles carry the same runtime.

Alternatives

  • Removing Iter's *[Symbol.iterator] (about 40 bytes gzipped): debugListEntries takes any Iterable, an Iter among them.
  • Fusing ok_or(e)? into one undefined test: smaller and allocation-free, but a translator change for about 10 bytes a site.
  • if (a) { if (b) S } as if (a && b) S, and else if chains as switch: Bun keeps both as written, but repeats like these gzip to little.

Follow-ups

Two open PRs grow the codec's bundle well past the target again:

  • #115 (with #101): +3728 bytes minified, +927 gzipped on main. Each adaptor class gains advanceBy, countItems, lastItem, and [Symbol.dispose], and class methods can't be tree-shaken, so every bundle using an adaptor carries them all.
  • #108: +1596 / +489, from the new Timestamp workloads in the fixture itself.

#104 takes off 105 / 29.

(written by Opus 5.5)

🤖 Generated with Claude Code

https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

kixelated and others added 3 commits October 27, 2026 05:16
Quest-Claim: ac82fbd881dca22c
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
@kixelated kixelated changed the title Smaller output from MIR perf(ts): leave out runtime the codec's bundle never calls Oct 27, 2026
@kixelated
kixelated marked this pull request as ready for review October 27, 2026 13:02
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T15:37:20.367850Z 88735f6 New commits
🔒 Security Review ✅ Completed 2026-10-27T15:39:30.437311Z 88735f6 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@kixelated kixelated left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review by review (OpenAI)

Reviewed commit: cdcb578

No actionable bugs found. The width-specific integer helpers preserve the existing signedness, limb normalization, shift checks, and fixed-width big-endian behavior. The structural inclusive-range check and type-only iterator declarations fit the runtime's supported representations.

Direction: focused tree-shaking improvements are preferable here to changing MIR lowering or adding a shared runtime driver. The modest 64/128-bit duplication is justified by keeping unused paths out of bundles; the plain error object also matches the documented representation.

Verification: static diff and surrounding-runtime inspection only. I did not run translation, tests, size measurements, or benchmarks; the reported size/performance results were not independently reproduced.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
@kixelated
kixelated merged commit 9655e37 into main Oct 27, 2026
1 check passed
@kixelated
kixelated deleted the quest/m2/ts-mir-size branch October 27, 2026 20:32
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