Skip to content

feat(ts): time Timestamp's checked_add and Ord in the bench - #108

Merged
kixelated merged 5 commits into
mainfrom
quest/m2/ts-bench-timestamp
Oct 27, 2026
Merged

kixelated merged 5 commits into
mainfrom
quest/m2/ts-bench-timestamp

Conversation

@kixelated

@kixelated kixelated commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

#89 moved Timestamp::checked_add and Ord (cross products compared in u128) off bigint, but no bench workload reached them, so Chrome never timed them.

Approach

  • fixtures/codec/src/bench.rs vendors moq-net's Timestamp (scale as a plain u64, not NonZero) with its checked_add and Ord, and adds two workloads beside time/u128:
    • op 10, time/checked-add/micros: a video track's frames stamped 33,333 µs apart by checked_add, from 1.9e14 µs since moq's epoch.
    • op 11, time/ord/micros-48k: that track interleaved with a 48 kHz audio track by Ord, one comparison per frame. Every value is under 2^53 and every cross product past it.
  • Hand-written route (bench/timestamp.ts): moq's own js/net Timestamp, whose isBefore compares across scales in bigint. It has no checked_add, so the route adds with its constructor's check. The first track has the finer scale, so a tie resolves the same way as Rust's (scale, value) tie-break.
  • Every route's output is checked against the wasm32 build first, as for the other workloads.
  • interleave orders with a < b, which the inherited lt from #107 now translates as partialCmp$PartialOrd(a, b) === -1, forwarding to cmp$Ord. The timings below were taken before that merge, with a.cmp(&b).is_lt() (cmp$Ord(a, b) < 0). After the merge, a one-round output check passed on every route and engine. Its timings are only a smoke test, and they show no break. I did not rerun the timed bench for one forwarding call.
  • Fixed a stale comment: rescale.ts said op 8, but it is op 9.

Measurements

Two just ts bench runs through quest gate, AMD Ryzen 9 5900XT. Median ns per timestamp, run 1 / run 2. There is no main baseline, since main has no such workload.

engine A/A spread, median / max workload hand-written translated A/A translated ÷ hand-written
Chrome 155 4.5%/33%, 2.9%/16% checked-add 8.41 / 7.02 12.4 / 10.8 8.23 / 10.9 1.47 / 1.54
ord 107 / 106 63.6 / 60.0 65.3 / 64.4 0.60 / 0.57
Firefox 158 4.4%/15%, 2.6%/31% checked-add 12.9 / 13.1 32.5 / 30.8 32.7 / 33.9 2.52 / 2.34
ord 49.9 / 47.2 119 / 115 118 / 116 2.39 / 2.44
Bun 1.4.2 4.9%/19%, 3.3%/21% checked-add 10.0 / 9.86 12.2 / 9.83 11.0 / 9.30 1.22 / 1.00
ord 121 / 114 100 / 97 93.8 / 93.7 0.83 / 0.85

Native is 0.74-0.76 ns (checked-add) and 1.55-1.60 ns (ord). wasm is 1.55-2.8 ns and 7.8-9.3 ns. In Chrome, translated Ord runs 1.7x faster than moq's bigint isBefore, and checked_add runs about 1.5x slower than a plain number add. Firefox runs both translated routes about 2.4x slower than hand-written, the same gap as on its time/u64 rows. The run-1 Chrome checked-add A/A gap (12.4 against 8.23) is the noise floor at ~10 ns per call.

Bundle size (minified, raw/gzip): translated 32765/10464 and hand-written 34067/10990. Both now carry the new workloads, and the hand-written route also pulls in moq's time.ts.

Impact

  • Public API: none. Bench and fixture only.

Alternatives

  • bigint for the hand-written route, as rescale.ts does: dropped in favor of moq's own Timestamp, which is what moq's TypeScript ships for ordering.
  • Using one workload that stamps and interleaves together: dropped, since it would not time the two paths apart.

Follow-ups

  • In translated stamp, the loop-invariant let step = Timestamp { .. } is rebuilt inside the loop (const step2 = { value: step, scale } per iteration, see expected/bench.ts). That is an allocation per call that native Rust doesn't make. It is a candidate quest for /quest-plan.

Checks

just check, just test, and quest check --base origin/main pass after merging main (with #107). Ran two full just ts bench runs (Node, Bun, Chrome, Firefox), and every route's output matched native Rust's.

(written by Opus 5.5)

🤖 Generated with Claude Code

https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

kixelated and others added 3 commits October 26, 2026 21:03
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
@kixelated kixelated changed the title Time Timestamp's checked_add and Ord in the TS benchmark feat(ts): time Timestamp's checked_add and Ord in the bench Oct 27, 2026
@kixelated
kixelated marked this pull request as ready for review October 27, 2026 05:49
@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-27T16:38:34.622699Z 2e115b5 New commits
🔒 Security Review ✅ Completed 2026-10-27T16:39:16.812347Z 2e115b5 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: ba5cf56

No actionable bugs found in the new Timestamp workloads, their generated translations, or benchmark integration. The inputs stay within the hand-written route's safe-number range, and the finer-scale-first ordering makes its equality behavior agree with Rust's tie-break for this workload.

Direction looks sound: separate stamping and interleaving cases expose the two paths without complicating the harness, while retaining output checks against wasm. These are workload-level timings (including timestamp updates/allocation), not isolated operator costs; the reported A/A variation also limits small performance claims.

Verification: source/snapshot review only. I did not execute tests or reproduce the browser benchmarks.

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
@kixelated
kixelated merged commit c329471 into main Oct 27, 2026
1 check passed
@kixelated
kixelated deleted the quest/m2/ts-bench-timestamp 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