Skip to content

feat(codspeed): time each benchmark with round markers - #201

Open
lvaroqui wants to merge 1 commit into
mainfrom
feat/time-benchmarks-with-round-markers
Open

lvaroqui wants to merge 1 commit into
mainfrom
feat/time-benchmarks-with-round-markers

Conversation

@lvaroqui

@lvaroqui lvaroqui commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

CodSpeed::start_benchmark and end_benchmark now take a timestamp right after the start command and right after the benchmarked code returns, both outside of the measured section, and send them as RoundStart/RoundEnd markers before the stop command.

The runner times a benchmark when it receives the commands that start and stop it, a while before the benchmark starts and after it ends. On a local run of the divan telemetry example, the runner's sample of a benchmark lasted 128–310 µs, while the code of the benchmarks emitting telemetry took 2–43 µs. The rounds bound the benchmark closely, so the runner can measure what happens during it from them, e.g. place the telemetry a benchmark emits.

The markers are sent whatever the instrumentation status: instrument hooks drops them outside of the CodSpeed runner and under Valgrind, so simulation measurements are unaffected. They are only sent by the builds that run each benchmark once, under cfg(codspeed): the compat layers only reach this code there, but the native harness (codspeed_bench!) also runs in walltime builds, whose rounds are the walltime loop's.

In memory mode, the runner forwards the markers with the memory results, and CodSpeed does not accept round markers there yet. The backend support has to be deployed before this is released, or memory runs lose their results.

Refs COD-3862: the issue also tracks the benchmark telemetry built on top of this.

@codspeed

codspeed Bot commented Oct 22, 2026

Copy link
Copy Markdown

Unable to generate the performance report

The run did not report any results. Please check the documentation to check your benchmarking setup.

@lvaroqui
lvaroqui force-pushed the feat/time-benchmarks-with-round-markers branch from d327961 to 70c6c8f Compare October 22, 2026 15:56
@lvaroqui
lvaroqui marked this pull request as ready for review October 22, 2026 15:59
@greptile-apps

greptile-apps Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The change reaches benchmark measurement across CodSpeed harnesses.

The timestamp change appears sound, but the added println! must satisfy the repository’s explicit output rule before merging.

Fix All in Claude CodeFindings

  1. P2 Added output breaks repository rule ▶
Fix with agent prompt
### Issue 1
crates/codspeed/build.rs:3
The new `println!` in `build.rs` violates the repository directive: “Never use `println!`/`eprintln!` in Rust; use tracing macros.” This requirement must be satisfied before merging. Use an allowed way to write the Cargo directive while preserving the stdout output Cargo needs.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Adds closely bounded round timestamps to benchmarks built with cfg(codspeed).

  • Benchmark runs now mark the code with start and end timestamps.

The added println! violates the repository’s output rule.

Acknowledgment: lvaroqui states that memory results require backend support before release because the backend does not yet accept these round markers. This known release dependency is not reported again.

Diagram

sequenceDiagram
    participant Harness
    participant Runtime as CodSpeed
    participant Hooks as Instrument hooks
    Harness->>Runtime: start_benchmark
    Runtime->>Hooks: Start command
    Note over Runtime: Save round_start
    Note over Runtime: Start direct measurement
    Harness->>Harness: Run benchmark
    Harness->>Runtime: end_benchmark
    Note over Runtime: Stop direct measurement
    Note over Runtime: Capture round_end
    Runtime->>Hooks: Send round timestamps
    Runtime->>Hooks: Stop command
Loading

Reviews (1) · Last reviewed commit: "feat(codspeed): time each benchmark with..." · Reviewed by Greptile

Comment thread crates/codspeed/build.rs
@lvaroqui
lvaroqui requested a review from not-matthias October 22, 2026 16:17

@not-matthias not-matthias left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, just small comments about comments :)

Comment thread crates/codspeed/src/codspeed.rs
Comment thread crates/codspeed/src/codspeed.rs Outdated
Comment thread crates/codspeed/src/codspeed.rs Outdated
The runner times a benchmark when it receives the commands that start
and stop it, a while before the benchmark starts and after it ends:
tens of microseconds, longer than many benchmarks.

Time each benchmark in the process too, right after the start command
and right after the benchmarked code returns, outside of the measured
section, and send these bounds as round markers before the stop command.
They are sent whatever the instrumentation status: instrument hooks
drops them outside of the CodSpeed runner and under Valgrind.

Only the builds that run each benchmark once, under `cfg(codspeed)`,
send them: the native harness also runs in walltime builds, whose
rounds are the walltime loop's.

Refs COD-3862
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lvaroqui
lvaroqui force-pushed the feat/time-benchmarks-with-round-markers branch from 70c6c8f to 5b54240 Compare October 23, 2026 09:47
@lvaroqui
lvaroqui added this pull request to stack #202 October 23, 2026 16:00
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.

2 participants