Repository navigation
Add bench() to the Rust worker::Interface trait - #8731
Conversation
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.
There was a problem hiding this comment.
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 Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
jasnell
left a comment
There was a problem hiding this comment.
Sweet, this knocks an item off my todo list nicely.
There was a problem hiding this comment.
✅ 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
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.