From ad768f637c3866e754affad71cb961c02b08ebc9 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Mon, 26 Oct 2026 21:03:52 -0700 Subject: [PATCH 1/3] chore(quest): claim quest/m2/ts-bench-timestamp.md Quest-Claim: d509131a2b9b1a66 From be87df207139eac4e7d1c617d5a2c94b4fc9fbf5 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Mon, 26 Oct 2026 21:17:36 -0700 Subject: [PATCH 2/3] feat(ts): time Timestamp's checked_add and Ord in the bench Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn --- ts/README.md | 10 +- ts/bench/main.ts | 5 +- ts/bench/moq.ts | 5 + ts/bench/rescale.ts | 4 +- ts/bench/timestamp.ts | 68 ++++++++++ ts/bench/workloads.ts | 11 +- ts/fixtures/codec/expected/bench.Timestamp.ts | 46 +++++++ ts/fixtures/codec/expected/bench.ts | 96 ++++++++++++++ ts/fixtures/codec/expected/lib.ts | 5 + ts/fixtures/codec/src/bench.rs | 117 +++++++++++++++++- 10 files changed, 356 insertions(+), 11 deletions(-) create mode 100644 ts/bench/timestamp.ts create mode 100644 ts/fixtures/codec/expected/bench.Timestamp.ts diff --git a/ts/README.md b/ts/README.md index db8981d4b..138f7f4e5 100644 --- a/ts/README.md +++ b/ts/README.md @@ -385,10 +385,12 @@ The codec fixture's `bench::run` holds the cases moq's own TypeScript benchmarks frame headers decoded as they arrive a few bytes at a time, which prices a decode that comes up `Short` and retries, iterator chains over bytes, a `BTreeMap` of 16, 256, and 4096 keys, and timestamps converted between timescales as moq-net's `Timestamp::convert` -does, whose products pass 2^53. Each runs four ways: natively, as wasm32 at moq-wasm's -size-optimized profile, hand-written (moq's `js/net` in `bench/moq.ts`, ES iterator -helpers in `bench/iter.ts`, a sorted array in `bench/sorted.ts`, and `bigint` in -`bench/rescale.ts`, as moq's `js/hang` converts timescales), and translated; every route's output must match +does, whose products pass 2^53, then added by its `checked_add` and ordered by its `Ord`, +whose cross products do too. Each runs four ways: natively, as wasm32 at moq-wasm's +size-optimized profile, hand-written (moq's `js/net` in `bench/moq.ts` and its `Timestamp` +in `bench/timestamp.ts`, ES iterator helpers in `bench/iter.ts`, a sorted array in +`bench/sorted.ts`, and `bigint` in `bench/rescale.ts`, as moq's `js/hang` converts +timescales), and translated; every route's output must match native Rust's first. The JS routes run minified, the same bundles whose size it reports, in Node, Bun, Chrome, and Firefox, with the WASM route's copies across the boundary timed apart from its compute, and an A/A copy of the diff --git a/ts/bench/main.ts b/ts/bench/main.ts index 76f19d6af..f8763b7a9 100644 --- a/ts/bench/main.ts +++ b/ts/bench/main.ts @@ -361,7 +361,7 @@ function render(): string { `- moq: ${text(["git", "-C", checkout, "rev-parse", "HEAD"])}`, ...engines.map((e) => `- ${e.engine}`), "", - "Each cell is nanoseconds per item (a varint, a frame header, a message, a byte iterated, a key, or a timestamp converted): the median", + "Each cell is nanoseconds per item (a varint, a frame header, a message, a byte iterated, a key, or a timestamp converted, added, or compared): the median", `of ${rounds} samples of at least ${sampleMs} ms, ± half their interquartile range. Each round runs`, `the JS routes and workloads in a new random order, from seed ${seed}. \`native\` is a release`, "build on the host, its workloads in a fixed order. `wasm` is the same", @@ -369,7 +369,8 @@ function render(): string { "copying the input in and the output out are timed apart. `hand-written` is moq's", "`js/net`, called as its own benchmarks call it, for `iter/` the same chain with ES", "iterator helpers (`bench/iter.ts`), for `btree/` a sorted array (`bench/sorted.ts`), and", - "for `time/` `bigint`, as moq's `js/hang` converts timescales (`bench/rescale.ts`).", + "for `time/` conversions `bigint`, as moq's `js/hang` converts timescales (`bench/rescale.ts`),", + "and for `time/checked-add` and `time/ord` moq's own `Timestamp` (`bench/timestamp.ts`).", "`A/A` is the translation loaded a second time: its", "gap from `translated` is the noise. A `reads` decode is the frame headers above as they", "arrive that many bytes at a time, so a header cut by a read comes up short and is", diff --git a/ts/bench/moq.ts b/ts/bench/moq.ts index efabbe9df..b55bbea54 100644 --- a/ts/bench/moq.ts +++ b/ts/bench/moq.ts @@ -16,6 +16,7 @@ import * as Varint from "moq/js/net/src/varint.ts"; import { iterate } from "./iter.ts"; import { rescale } from "./rescale.ts"; import { ordered } from "./sorted.ts"; +import { interleave, stamp } from "./timestamp.ts"; type Version = (typeof Lite)[keyof typeof Lite]; @@ -54,6 +55,10 @@ export function run(input: Uint8Array): Uint8Array | Promise { return ordered(data); case 9: return rescale(selector, data); + case 10: + return stamp(data); + case 11: + return interleave(data); default: throw new Error(`unknown workload ${op}`); } diff --git a/ts/bench/rescale.ts b/ts/bench/rescale.ts index 63eee647c..86bb7b003 100644 --- a/ts/bench/rescale.ts +++ b/ts/bench/rescale.ts @@ -1,9 +1,9 @@ -// The timestamp workloads' hand-written route: `bench.rs`'s op 8 with `bigint`, as moq's +// The timestamp workloads' hand-written route: `bench.rs`'s op 9 with `bigint`, as moq's // TypeScript converts timescales (`wallClockTime` in `js/hang/src/catalog/clock.ts`). const MAX_TIMESTAMP = (1n << 61n) - 1n; -/** Convert every timestamp, as `bench::run`'s op 8 does: how many, how many overflowed, and the last. */ +/** Convert every timestamp, as `bench::run`'s op 9 does: how many, how many overflowed, and the last. */ export function rescale(selector: number, data: Uint8Array): Uint8Array { const view = new DataView(data.buffer, data.byteOffset, data.byteLength); const [count, start, step, from, to] = [0, 1, 2, 3, 4].map((i) => view.getBigUint64(i * 8)); diff --git a/ts/bench/timestamp.ts b/ts/bench/timestamp.ts new file mode 100644 index 000000000..55a224a54 --- /dev/null +++ b/ts/bench/timestamp.ts @@ -0,0 +1,68 @@ +// The `Timestamp` workloads' hand-written route: `bench.rs`'s ops 10 and 11 with moq's own +// TypeScript `Timestamp`, whose values are numbers and whose `isBefore` compares across +// scales in `bigint`. +// +// `moq/` imports resolve to the moq checkout when `main.ts` bundles this file. + +import { Timescale, Timestamp } from "moq/js/net/src/time.ts"; + +/** Read the `u64`s `data` holds, as numbers: the workloads keep them under 2^53. */ +function params(data: Uint8Array): number[] { + const view = new DataView(data.buffer, data.byteOffset, data.byteLength); + return Array.from({ length: data.byteLength / 8 }, (_, i) => Number(view.getBigUint64(i * 8))); +} + +function u64s(...values: number[]): Uint8Array { + const out = new Uint8Array(values.length * 8); + const view = new DataView(out.buffer); + values.forEach((v, i) => view.setBigUint64(i * 8, BigInt(v))); + return out; +} + +/** Op 10: a track's frames stamped one duration apart. */ +export function stamp(data: Uint8Array): Uint8Array { + const [count, start, step, scale] = params(data); + const duration = new Timestamp(step, Timescale(scale)); + let time = new Timestamp(start, Timescale(scale)); + let stamped = 0; + for (let i = 0; i < count; i++) { + time = checkedAdd(time, duration); + stamped++; + } + return u64s(stamped, 0, time.value); +} + +// moq's `Timestamp` has no `checked_add`; this is Rust's, except that the constructor +// throws past 2^53, which the workload stays under. +function checkedAdd(a: Timestamp, b: Timestamp): Timestamp { + if (a.scale !== b.scale) throw new RangeError("mismatched timescales"); + return new Timestamp(a.value + b.value, a.scale); +} + +/** + * Op 11: two tracks interleaved in presentation order. `isBefore` has no tie-break, as + * Rust's `Ord` does by `(scale, value)`; the first track is the finer-scaled, so a tie + * takes the second either way. + */ +export function interleave(data: Uint8Array): Uint8Array { + const [count, aStart, aStep, aScale, bStart, bStep, bScale] = params(data); + let a = new Timestamp(aStart, Timescale(aScale)); + let b = new Timestamp(bStart, Timescale(bScale)); + let fromA = 0; + let fromB = 0; + let switches = 0; + let lastA = true; + for (let i = 0; i < count; i++) { + const takeA = a.isBefore(b); + if (takeA) { + a = new Timestamp(a.value + aStep, a.scale); + fromA++; + } else { + b = new Timestamp(b.value + bStep, b.scale); + fromB++; + } + if (takeA !== lastA) switches++; + lastA = takeA; + } + return u64s(fromA, fromB, switches); +} diff --git a/ts/bench/workloads.ts b/ts/bench/workloads.ts index 2b5bc6559..e2e0cf574 100644 --- a/ts/bench/workloads.ts +++ b/ts/bench/workloads.ts @@ -5,7 +5,7 @@ export interface Workload { /** What is coded, such as `varint/quic/2B` or `frames/video/lite-07`, iterated, or converted. */ name: string; - op: "encode" | "decode" | "iterate" | "map" | "convert" | "handoff"; + op: "encode" | "decode" | "iterate" | "map" | "convert" | "add" | "compare" | "handoff"; /** Varints, frame headers, messages, items, keys, timestamps, or handoffs per call, which each time is divided by. */ items: number; input: Uint8Array; @@ -84,6 +84,15 @@ export function workloads(encode: (input: Uint8Array) => Uint8Array): Workload[] out.push({ name: `time/${type}/${name}`, op: "convert", items: count, input }); } } + + // The same frames stamped by moq-net's `Timestamp::checked_add` (op 10), and interleaved + // by its `Ord` (op 11) with an audio track's at 48 kHz, from the same instant: every + // value is under 2^53, as moq's TypeScript keeps them, and every cross product past it. + const video = [start, 33_333n, 1_000_000n]; + const audio = [(start * 48_000n) / 1_000_000n, 1_024n, 48_000n]; + const time = (op: number, params: bigint[]) => Uint8Array.of(op, 0, ...[BigInt(count), ...params].flatMap(u64)); + out.push({ name: "time/checked-add/micros", op: "add", items: count, input: time(10, video) }); + out.push({ name: "time/ord/micros-48k", op: "compare", items: count, input: time(11, [...video, ...audio]) }); return out; } diff --git a/ts/fixtures/codec/expected/bench.Timestamp.ts b/ts/fixtures/codec/expected/bench.Timestamp.ts new file mode 100644 index 000000000..63bfb908a --- /dev/null +++ b/ts/fixtures/codec/expected/bench.Timestamp.ts @@ -0,0 +1,46 @@ +// Generated by rust2-ts. Do not edit. + +import * as rt from "./rt.ts"; +import { bounded } from "./bench.ts"; + +/** moq-net's `Timestamp`, with the scale it keeps as a `NonZero` unwrapped. */ +export interface Timestamp { + value: rt.u64; + scale: rt.u64; +} + +/** + * The sum, or `None` across scales or past [`MAX_TIMESTAMP`], as moq-net's + * `Timestamp::checked_add` returns `TimeOverflow`. + */ +export function checkedAdd(self: Timestamp, rhs: Timestamp): Timestamp | undefined { + if (!rt.u64Ne(self.scale, rhs.scale)) { + const _6: rt.u64 | undefined = rt.u64CheckedAdd(self.value, rhs.value); + if (_6 === undefined) { + return undefined; + } + const _11: rt.u64 | undefined = bounded(rt.u128Cast(_6)); + if (_11 === undefined) { + return undefined; + } + return { value: _11, scale: self.scale }; + } + return undefined; +} + +/** + * moq-net's temporal order: across scales, the cross products in `u128`, with a tie + * broken by `(scale, value)`. + */ +export function cmp$Ord(self: Timestamp, other: Timestamp): rt.Ordering { + if (!rt.u64Eq(self.scale, other.scale)) { + return rt.orderingThen(rt.orderingThen(rt.cmp(rt.u128Mul(rt.u128Cast(self.value), rt.u128Cast(other.scale)), rt.u128Mul(rt.u128Cast(other.value), rt.u128Cast(self.scale))), (): rt.Ordering => { + return rt.cmp(self.scale, other.scale); + }, true), (): rt.Ordering => { + return rt.cmp(self.value, other.value); + }, true); + } + return rt.cmp(self.value, other.value); +} + +//# sourceMappingURL=bench.Timestamp.ts.map diff --git a/ts/fixtures/codec/expected/bench.ts b/ts/fixtures/codec/expected/bench.ts index f71940aa4..eee1efb57 100644 --- a/ts/fixtures/codec/expected/bench.ts +++ b/ts/fixtures/codec/expected/bench.ts @@ -1,6 +1,8 @@ // Generated by rust2-ts. Do not edit. import * as rt from "./rt.ts"; +import { copy$Timestamp } from "./lib.ts"; +import * as Timestamp from "./bench.Timestamp.ts"; import type * as DecodeError from "./coding/decode.DecodeError.ts"; import * as Decoder from "./coding/decode.Decoder.ts"; import type * as EncodeError from "./coding/encode.EncodeError.ts"; @@ -38,6 +40,10 @@ export function run(input: rt.ByteSlice): rt.ByteVec { ordered(_9[1], out); } else if (op === 9) { rescale(selector, _9[1], out); + } else if (op === 10) { + stamp(_9[1], out); + } else if (op === 11) { + interleave(_9[1], out); } else { decoded(decodeGroup(_9[1], liteVersion(selector), out), out); } @@ -413,6 +419,96 @@ export function bounded(value: rt.u128): rt.u64 | undefined { return rt.u64Cast(value); } +/** + * A track's frames stamped one duration apart by [`Timestamp::checked_add`], as a + * publisher stamps them. How many were stamped, how many overflowed, and the last. + */ +export function stamp(data: rt.ByteSlice, out: rt.ByteVec): void { + const _5: [rt.u64, rt.ByteSlice] = takeU64(data); + const count: rt.u64 = _5[0]; + const _8: [rt.u64, rt.ByteSlice] = takeU64(_5[1]); + const start: rt.u64 = _8[0]; + const _11: [rt.u64, rt.ByteSlice] = takeU64(_8[1]); + const step: rt.u64 = _11[0]; + const scale: rt.u64 = takeU64(_11[1])[0]; + let time: Timestamp.Timestamp = { value: start, scale }; + let stamped: rt.u64 = 0; + let overflowed: rt.u64 = 0; + const iter: rt.Range = new rt.Range(0, count, rt.u64Step); + while (true) { + const step2: Timestamp.Timestamp = { value: step, scale }; + const _22: rt.u64 | rt.Done = iter.next(); + if (_22 === rt.DONE) { + break; + } + const _25: Timestamp.Timestamp | undefined = Timestamp.checkedAdd(time, step2); + if (_25 === undefined) { + overflowed = rt.u64Add(overflowed, 1); + } else { + time = _25; + stamped = rt.u64Add(stamped, 1); + } + } + putU64(out, stamped); + putU64(out, overflowed); + putU64(out, time.value); +} + +/** + * Two tracks' frames, each one duration after the last at its own scale, interleaved in + * presentation order by [`Timestamp`]'s `Ord`, as a muxer interleaves them: one + * comparison per frame taken. How many came from each track, and how many times the + * interleave switched tracks. + */ +export function interleave(data: rt.ByteSlice, out: rt.ByteVec): void { + const _5: [rt.u64, rt.ByteSlice] = takeU64(data); + const count: rt.u64 = _5[0]; + const _9: [Timestamp.Timestamp, rt.u64, rt.ByteSlice] = track(_5[1]); + const a: Timestamp.Timestamp = copy$Timestamp(_9[0]); + const aStep: rt.u64 = _9[1]; + const _12: [Timestamp.Timestamp, rt.u64, rt.ByteSlice] = track(_9[2]); + const b: Timestamp.Timestamp = copy$Timestamp(_12[0]); + const bStep: rt.u64 = _12[1]; + let fromA: rt.u64 = 0; + let fromB: rt.u64 = 0; + let switches: rt.u64 = 0; + let lastA: boolean = true; + const iter: rt.Range = new rt.Range(0, count, rt.u64Step); + while (true) { + const _21: rt.u64 | rt.Done = iter.next(); + if (_21 === rt.DONE) { + break; + } + const takeA: boolean = Timestamp.cmp$Ord(a, b) < 0; + if (!takeA) { + const _30: rt.u64 = rt.u64Add(b.value, bStep); + b.value = _30; + fromB = rt.u64Add(fromB, 1); + } else { + const _28: rt.u64 = rt.u64Add(a.value, aStep); + a.value = _28; + fromA = rt.u64Add(fromA, 1); + } + if (takeA !== lastA) { + switches = rt.u64Add(switches, 1); + } + lastA = takeA; + } + putU64(out, fromA); + putU64(out, fromB); + putU64(out, switches); +} + +/** A track's first timestamp and its frame duration: start, step, and scale. */ +export function track(data: rt.ByteSlice): [Timestamp.Timestamp, rt.u64, rt.ByteSlice] { + const _4: [rt.u64, rt.ByteSlice] = takeU64(data); + const value: rt.u64 = _4[0]; + const _7: [rt.u64, rt.ByteSlice] = takeU64(_4[1]); + const step: rt.u64 = _7[0]; + const _10: [rt.u64, rt.ByteSlice] = takeU64(_7[1]); + return [{ value, scale: _10[0] }, step, _10[1]] as [Timestamp.Timestamp, rt.u64, rt.ByteSlice]; +} + export function decodeGroup(wire: rt.ByteSlice, version: Version.Version, out: rt.ByteVec): rt.Result { const _6: rt.Result<[Group.Group, rt.usize], DecodeError.DecodeError> = Group.decodeSlice$Decode_Version(wire, version); if (_6.ok) { diff --git a/ts/fixtures/codec/expected/lib.ts b/ts/fixtures/codec/expected/lib.ts index 28e4aec41..4a5725376 100644 --- a/ts/fixtures/codec/expected/lib.ts +++ b/ts/fixtures/codec/expected/lib.ts @@ -1,5 +1,6 @@ // Generated by rust2-ts. Do not edit. +import type * as Timestamp from "./bench.Timestamp.ts"; import type * as Form from "./coding/varint.Form.ts"; import type * as Version from "./coding/version.Version.ts"; @@ -10,6 +11,10 @@ export function copy$Form(v: Form.Form): Form.Form { return v; } +export function copy$Timestamp(v: Timestamp.Timestamp): Timestamp.Timestamp { + return { value: v.value, scale: v.scale }; +} + export function copy$Version(v: Version.Version): Version.Version { return { _0: v._0 }; } diff --git a/ts/fixtures/codec/src/bench.rs b/ts/fixtures/codec/src/bench.rs index c1cf3e690..d7f6ea531 100644 --- a/ts/fixtures/codec/src/bench.rs +++ b/ts/fixtures/codec/src/bench.rs @@ -3,9 +3,10 @@ //! the workload and the second its wire format; an encode's output is the matching //! decode's input. Op 6 runs iterator chains over its bytes instead, as moq-net's model //! writes them, op 7 decodes frame headers as they arrive a few bytes at a time, op 8 -//! keeps a `BTreeMap`, as moq-net's model keeps its state, and op 9 converts timestamps -//! between timescales. +//! keeps a `BTreeMap`, as moq-net's model keeps its state, op 9 converts timestamps +//! between timescales, and ops 10 and 11 add and order them as moq-net's `Timestamp` does. +use std::cmp::Ordering; use std::collections::BTreeMap; use crate::coding::{Decode, DecodeError, Decoder, Encode, EncodeError, Encoder, Form, varint}; @@ -32,6 +33,8 @@ pub fn run(input: &[u8]) -> Vec { 7 => decoded(decode_split(data, lite_version(selector), &mut out), &mut out), 8 => ordered(data, &mut out), 9 => rescale(selector, data, &mut out), + 10 => stamp(data, &mut out), + 11 => interleave(data, &mut out), _ => decoded(decode_group(data, lite_version(selector), &mut out), &mut out), } out @@ -278,6 +281,116 @@ const fn bounded(value: u128) -> Option { } } +/// moq-net's `Timestamp`, with the scale it keeps as a `NonZero` unwrapped. +#[derive(Clone, Copy, PartialEq, Eq)] +struct Timestamp { + value: u64, + scale: u64, +} + +impl Timestamp { + /// The sum, or `None` across scales or past [`MAX_TIMESTAMP`], as moq-net's + /// `Timestamp::checked_add` returns `TimeOverflow`. + const fn checked_add(self, rhs: Self) -> Option { + if self.scale != rhs.scale { + return None; + } + match self.value.checked_add(rhs.value) { + Some(value) => match bounded(value as u128) { + Some(value) => Some(Self { + value, + scale: self.scale, + }), + None => None, + }, + None => None, + } + } +} + +impl PartialOrd for Timestamp { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl Ord for Timestamp { + /// moq-net's temporal order: across scales, the cross products in `u128`, with a tie + /// broken by `(scale, value)`. + fn cmp(&self, other: &Self) -> Ordering { + if self.scale == other.scale { + return self.value.cmp(&other.value); + } + let lhs = self.value as u128 * other.scale as u128; + let rhs = other.value as u128 * self.scale as u128; + lhs.cmp(&rhs) + .then_with(|| self.scale.cmp(&other.scale)) + .then_with(|| self.value.cmp(&other.value)) + } +} + +/// A track's frames stamped one duration apart by [`Timestamp::checked_add`], as a +/// publisher stamps them. How many were stamped, how many overflowed, and the last. +fn stamp(data: &[u8], out: &mut Vec) { + let (count, data) = take_u64(data); + let (start, data) = take_u64(data); + let (step, data) = take_u64(data); + let (scale, _) = take_u64(data); + let step = Timestamp { value: step, scale }; + let mut time = Timestamp { value: start, scale }; + let (mut stamped, mut overflowed) = (0, 0); + for _ in 0..count { + match time.checked_add(step) { + Some(next) => { + time = next; + stamped += 1; + } + None => overflowed += 1, + } + } + put_u64(out, stamped); + put_u64(out, overflowed); + put_u64(out, time.value); +} + +/// Two tracks' frames, each one duration after the last at its own scale, interleaved in +/// presentation order by [`Timestamp`]'s `Ord`, as a muxer interleaves them: one +/// comparison per frame taken. How many came from each track, and how many times the +/// interleave switched tracks. +fn interleave(data: &[u8], out: &mut Vec) { + let (count, data) = take_u64(data); + let (mut a, a_step, data) = track(data); + let (mut b, b_step, _) = track(data); + let (mut from_a, mut from_b, mut switches) = (0, 0, 0); + let mut last_a = true; + for _ in 0..count { + // Not `a < b`: rust2-ts does not lower `PartialOrd`'s default `lt` yet. + let take_a = a.cmp(&b).is_lt(); + if take_a { + a.value += a_step; + from_a += 1; + } else { + b.value += b_step; + from_b += 1; + } + if take_a != last_a { + switches += 1; + } + last_a = take_a; + } + put_u64(out, from_a); + put_u64(out, from_b); + put_u64(out, switches); +} + +/// A track's first timestamp and its frame duration: start, step, and scale. +fn track(data: &[u8]) -> (Timestamp, u64, &[u8]) { + let (value, data) = take_u64(data); + let (step, data) = take_u64(data); + let (scale, data) = take_u64(data); + (Timestamp { value, scale }, step, data) +} + fn decode_group(wire: &[u8], version: lite::Version, out: &mut Vec) -> Result<(), DecodeError> { let (group, used) = lite::Group::decode_slice(wire, version)?; put_u64(out, group.subscribe); From ba5cf563d60f88bfc56d574dc06ea3d43aaecc9b Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Mon, 26 Oct 2026 22:49:07 -0700 Subject: [PATCH 3/3] chore(quest): finish ts-bench-timestamp Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn --- quest/m2/README.md | 1 - quest/m2/ts-bench-timestamp.md | 21 --------------------- quest/m2/ts-cmp-defaults.md | 1 + ts/fixtures/codec/src/bench.rs | 2 +- 4 files changed, 2 insertions(+), 23 deletions(-) delete mode 100644 quest/m2/ts-bench-timestamp.md diff --git a/quest/m2/README.md b/quest/m2/README.md index fa94622f3..4e49d9aab 100644 --- a/quest/m2/README.md +++ b/quest/m2/README.md @@ -29,7 +29,6 @@ The fork's feature quests folded into the [exporter](/quest/m1/ffi-export.md); - [Byte slices without objects](/quest/m2/ts-byte-views.md) - splitting a `&[u8]` allocates nothing, neither a chunk view nor a `ByteSlice` - [Smaller output from MIR](/quest/m2/ts-mir-size.md) - the bench's bundles shrink back to THIR's sizes, coroutine classes first - [An A/A control that measures noise](/quest/m2/ts-bench-aa.md) - `just ts bench`'s A/A measures only noise, in every engine -- [Time Timestamp's checked_add and Ord](/quest/m2/ts-bench-timestamp.md) - the `u128` paths #89 sped up get a Chrome timing - [Drop in the TypeScript translator](/quest/m2/ts-drop.md) - every value that drops in moq-net and kio drops where Rust drops it - [Async in the TypeScript translator](/quest/m2/ts-async.md) - moq-net's and kio's async code translates with Rust's lazy futures - [Shared ownership](/quest/m2/ts-shared.md) - `Arc`/`Rc`/`Weak` keep exact counts, and locks and atomics become plain values diff --git a/quest/m2/ts-bench-timestamp.md b/quest/m2/ts-bench-timestamp.md deleted file mode 100644 index 6d00143d6..000000000 --- a/quest/m2/ts-bench-timestamp.md +++ /dev/null @@ -1,21 +0,0 @@ -# [XS] Time Timestamp's checked_add and Ord in the TS benchmark - -## Goal - -`just ts bench` times moq-net's `Timestamp::checked_add` and `Ord`, whose `u128` -cross products the wide runtime now computes in limbs, in Chrome, Firefox and Bun -with the A/A control. - -## Plan - -Decided with the maintainer on 2026-10-26, from -[#89](https://github.com/kixelated/rust2/pull/89): its Node/Bun microbench put -`checked_add` and `saturating_sub` 20-100x faster, but no bench workload reaches them, -so Chrome never timed them. - -- Add the workload beside `time/u128`, drawing its inputs from the wasm32 build as - the other workloads do. -- The remaining 128-bit `bigint` paths (bitwise ops, shifts, `leading_*`, `try_from`) - stay until a consumer reaches them. - -Public API: none. diff --git a/quest/m2/ts-cmp-defaults.md b/quest/m2/ts-cmp-defaults.md index 6e5aef8f2..2e6acd96e 100644 --- a/quest/m2/ts-cmp-defaults.md +++ b/quest/m2/ts-cmp-defaults.md @@ -19,5 +19,6 @@ them. - Cover a hand-written `partial_cmp` that returns `None`, and a type whose `eq` and `partial_cmp` disagree, in the differential tests. - Report moq-net's census before and after. +- Then `bench.rs`'s `interleave` can order its timestamps with `a < b`, as Rust writes it. Public API: the translator's output. diff --git a/ts/fixtures/codec/src/bench.rs b/ts/fixtures/codec/src/bench.rs index d7f6ea531..74505411f 100644 --- a/ts/fixtures/codec/src/bench.rs +++ b/ts/fixtures/codec/src/bench.rs @@ -364,7 +364,7 @@ fn interleave(data: &[u8], out: &mut Vec) { let (mut from_a, mut from_b, mut switches) = (0, 0, 0); let mut last_a = true; for _ in 0..count { - // Not `a < b`: rust2-ts does not lower `PartialOrd`'s default `lt` yet. + // Not `a < b`, which needs `PartialOrd`'s default `lt`: /quest/m2/ts-cmp-defaults.md. let take_a = a.cmp(&b).is_lt(); if take_a { a.value += a_step;