Skip to content

Add bench() to the Rust worker::Interface trait - #8731

Merged
bartlomieju merged 2 commits into
mainfrom
biwanczuk/rust-interface-bench
Nov 23, 2026
Merged

bartlomieju merged 2 commits into
mainfrom
biwanczuk/rust-interface-bench

Conversation

@bartlomieju

@bartlomieju bartlomieju commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

The Rust worker::Interface trait predates WorkerInterface::bench() and
never got the method, so a Rust implementation wrapped for C++ answered
UNIMPLEMENTED, and a Rust decorator such as PromisedInterface hid the
bench handler of the worker behind it. As more of the WorkerInterface
chain moves to Rust, bench() has to pass through it like other events.

Interface::bench() takes an encoded BenchParams and returns the encoded
BenchReport.Group. Its default fails as UNIMPLEMENTED, matching C++.
RustWorkerInterface bridges it to C++, a new worker_bench shim lets
CxxWorkerInterface call the wrapped C++ worker, and CxxWorkerInterface
and PromisedInterface forward it. No behavior visible to Workers
changes. New C++ and Rust tests cover the round trip, forwarding, and
the default.

The Rust worker::Interface trait predates WorkerInterface::bench(), so it
never got the method. A Rust implementation wrapped for C++
(RustWorkerInterface) fell through to C++'s default and answered
UNIMPLEMENTED, and CxxWorkerInterface had no way to call bench() on the C++
worker it wraps. A Rust decorator such as PromisedInterface in front of a
worker would hide the worker's bench handler. `workerd bench` doesn't go
through one today, but the Rust implementations that sit between the server
and WorkerEntrypoint will.

Interface::bench() takes an encoded BenchParams message in words and
returns the encoded BenchReport.Group the handler filled in, the
convention the server crate already uses for worker_bench. Its default
fails with UNIMPLEMENTED and the message C++ uses, so implementations that
had no bench() keep answering as before. RustWorkerInterface encodes the
params, calls the Rust implementation and copies the returned group's
error, overhead and cases into the caller's report; a new worker_bench
shim lets CxxWorkerInterface call the wrapped C++ worker's bench().
CxxWorkerInterface and PromisedInterface forward it.
@bartlomieju
bartlomieju requested review from a team as code owners November 20, 2026 10:21

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Superseded by the review of 7ce5753d.

This review, of 4f29599c

✅ Approved — No issues found. The bench() forwarding across the Rust/C++ boundary handles lifetimes, alignment and the caller-owned report fields correctly, and the tests cover it.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

No issues found. The encoded bench messages pass only between in-process C++ and Rust components; workerd bench generates them, and no Worker input reaches them. Buffer lifetimes and alignment are sound. The traversal limit is lifted only when reading the report returned by the in-process implementation.


📖 AGENTS.md: ✅ LGTM

No issues found.


📋 Code Quality: ✅ LGTM

No issues found.


⚡ Performance: ✅ LGTM

No issues found.


📝 Documentation: ✅ LGTM

No issues found.


Reviewed commit: 4f29599c

@codecov-commenter

codecov-commenter commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 45 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.73%. Comparing base (0a09936) to head (7ce5753).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/rust/worker/ffi.c++ 0.00% 32 Missing ⚠️
src/rust/worker/ffi.rs 0.00% 7 Missing ⚠️
src/rust/worker/cxx_worker.rs 0.00% 2 Missing ⚠️
src/rust/worker/lib.rs 0.00% 2 Missing ⚠️
src/rust/worker/promised.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8731      +/-   ##
==========================================
- Coverage   67.75%   67.73%   -0.02%     
==========================================
  Files         846      846              
  Lines      214951   214996      +45     
  Branches    32584    32587       +3     
==========================================
  Hits       145633   145633              
- Misses      50077    50122      +45     
  Partials    19241    19241              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jasnell jasnell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sweet, this knocks an item off my todo list nicely.

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Approved — No issues found. The bench() forwarding across the Rust/C++ boundary is sound, and the new default and its test match the C++ behaviour.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🔒 Security: ✅ LGTM

No issues found. The encoded bench messages pass only between in-process C++ and Rust components, and the new default takes no external input. The traversal limit is lifted only when reading the report returned by the in-process implementation.


📖 AGENTS.md: ✅ LGTM

No issues found.


📋 Code Quality: ✅ LGTM

No issues found. The new default bench() and its Rust unit test are correct. FFI lifetimes, 8-byte alignment of the word buffers, and copying back only error, overhead and cases (keeping the caller's name and startup) are all handled correctly, and the tests cover them.


⚡ Performance: ✅ LGTM

No issues found. This is a bench-only path: the FFI copies happen once per bench call, and none of it is on a hot path.


📝 Documentation: ✅ LGTM

No issues found.


Reviewed commit: 7ce5753d

@bartlomieju
bartlomieju enabled auto-merge (squash) November 23, 2026 08:01
@bartlomieju
bartlomieju merged commit 1adff5d into main Nov 23, 2026
24 checks passed
@bartlomieju
bartlomieju deleted the biwanczuk/rust-interface-bench branch November 23, 2026 08:02
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.

4 participants