Make Rust JSG promise reactions as cheap as C++ JSG's #8806
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 303 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.342
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #8806"
general
weight: 0.35
jasnell
jsg-bench had no promise cases. With new ones, a Rust
#[jsg_method]that returns or takes ajsg::Promisewas 2.2-4.6x slower than the C++ JSG method returningjsg::Promise, on a cross-language LTO build. There were two causes. Rust converted a typed promise's value with the generalthen_or_catch(), which costs a new Wrappable, an opaque wrapper, a second function that only rethrows a rejection, and aTracedGlobalof the creator. C++ JSG'sthenWrap()/thenUnwrap()is one function with the creator as its V8 data. Also, every Rust reaction function was created as a constructor, so V8 built a prototype object for each one, where C++ JSG passesConstructorBehavior::kThrow.In this patch jsg-bench gets promise cases for both bindings. The conversion reactions become one function added with a fulfilled-only
Then(), through a single shim, andfunction_new()takes the constructor behaviour, so promise reactions are created withkThrow.Function::newandFunction::from_callback, whose functions JavaScript can call and construct, are unchanged.Rust/C++ CPU time per call, measured with
--config=cross-ltoand jsg-bench linked like workerd (#8790). Before and after binaries alternated on one executor, 4 rounds x 5 repetitions. Two runs agreed within 5%; the table shows the first. Each call also runs the microtasks, so the reactions are timed.| Case | C++ | Rust before | Rust after | Speedup | Rust/C++ after |
|---|---:|---:|---:|---:|---:|
|
promise/resolved-void| 404 ns | 1863 ns | 449 ns | 4.1x | 1.03x ||
promise/resolved(Promise<f64>) | 763 ns | 2165 ns | 877 ns | 2.5x | 1.16x ||
promise/then-promise| 2027 ns | 5504 ns | 2339 ns | 2.4x | 1.18x ||
promise/then-value| 1828 ns | 4070 ns | 2140 ns | 1.9x | 1.18x |promise/throw-captured(Rust 0.14x of C++) andpromise/untyped-voiddon't change.Nothing a Worker can observe changes, so there is no compat flag. JavaScript never sees reaction functions. A rejection still passes through in the same number of ticks, a value of the wrong type still rejects with the same TypeError, and a method's resource stays alive until its promise settles.
returned_promise_keeps_its_resource_alivecovers that last point, and it fails if the creator isn't kept as the reaction's data.//src/rust/..., the memory-cache Rust tests and the jsg-bench smoke test pass, and each commit builds and passes clippy on its own.