Skip to content

feat(benchmarks): the tick cost as a committed, repeatable measurement - #10

Closed
Immanuel-Fowler wants to merge 1 commit into
feat/boundary-ladder-benchmarkfrom
feat/tick-cost-benchmark
Closed

Immanuel-Fowler wants to merge 1 commit into
feat/boundary-ladder-benchmarkfrom
feat/tick-cost-benchmark

Conversation

@Immanuel-Fowler

Copy link
Copy Markdown
Owner

Stacked on #9 (feat/boundary-ladder-benchmark); merge that first.

What

benchmarks/tick_cost/run.py turns the 8 ns tick_sync and ~1.5 ns host-call figures, which lived only in the 0.8.1 release notes and an ignored test, into a committed, repeatable measurement with the same environment header as the boundary ladder.

Six small library programs are built with build --lib and driven by one Rust host through tick_sync on a current-thread runtime in release mode: an empty tick, one host call, five host calls, an instance let increment, a shared let increment, and one host-fired event per tick. Each case is warmed up with five rounds, then timed for 21 rounds of 200,000 ticks; the median round is reported with the fastest and the p90 round, next to the Host trait method called through its vtable alone, which is the floor for a host call. Output: tick_cost.csv, tick_cost.json, tick_cost.md under benchmarks/results/. The README's table is pasted from the generated Markdown.

Found and fixed on the way

The shared let case would not compile: a block whose tail statement touches shared state (on_tick(dt: float) { hits = hits + 1 }, but equally while c { hits = hits + 1 } and if c { hits = hits + 1 }) was compiled without the lock guard and reached rustc as an unknown __shared. A v0.13.0 gap in every mode. Fixed in compile_block_inner: a block tail that touches shared state takes the lock exactly as a statement does, and one that also waits is refused with the existing message. Regression tests: runtime_shared_state_in_a_block_tail_takes_the_lock and library_shared_state_in_hooks.

Changelog entries under [Unreleased]. No version bump.

🤖 Generated with Claude Code

The 8 ns tick_sync and ~1.5 ns host-call figures lived in the 0.8.1
release notes and an ignored test. benchmarks/tick_cost/run.py builds
six small library programs, drives each through tick_sync on a
current-thread runtime in release mode, and reports the median of 21
rounds of 200,000 ticks beside the Host trait method called through its
vtable alone, with the same environment header as the boundary ladder.
The fastest round is reported too and is the figure to derive from: on
Apple Silicon the scheduler moves the thread between core types during
a run, so medians overlap within a few nanoseconds.

The shared let case would not compile, which turned up two 0.13.0 gaps
in every mode. A block whose tail statement touches shared state — an
on_tick body, a while body, an if branch — was compiled without the
lock and reached rustc as an unknown __shared; a block tail now takes
the lock as a statement does, and one that also waits is refused with
the existing message. And a let whose initialiser reads shared state
was wrapped whole in the lock's block, so its binding was gone on the
next line; the lock now wraps only the initialiser.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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