← Back to Pull requests

Link jsg-bench like the workerd binary so cross-language LTO applies to it #8790

Closed
unknown closed this pull request without merging on Nov 24, 2026 02:50 UTC
View on GitHub
unknown unknown commented on Nov 21, 2026 17:24 UTC
Author

Every wd_cc_benchmark links like a test binary: on Linux, dynamically with one shared library per cc_library, and with linkopts_default, whose -Wl,--lto-O0 turns off link-time optimization. So --config=cross-lto, which docs/benchmarking.md recommends, has no effect on bench-jsg. Nothing is inlined across the Rust/C++ boundary, each V8 call from Rust is several out-of-line calls, and the Rust/C++ ratios come out 2-6x larger than in a workerd binary built with cross-language LTO.

In this patch wd_cc_benchmark takes a tool argument, following the convention in wd_rust_binary. With tool = True a benchmark links statically with linkopts_tool, as the workerd binary does. bench-jsg sets it, and every other benchmark keeps its current linking, so CodSpeed baselines don't move. A new manual bench-report target runs the benchmark on the test executor and keeps its JSON reports as test outputs. That makes remote measurement possible: bazel test normally runs a benchmark only once as a dry run, and on macOS a remote build produces a Linux binary that can't run locally. The jsg-bench README documents the command, and docs/benchmarking.md explains when tool = True is needed.

| Case | C++ | Rust before | Rust after | Rust speedup | Rust/C++ before | Rust/C++ after |
|---|---:|---:|---:|---:|---:|---:|
| dispatch/noop | 11.9 ns | 31.8 ns | 12.6 ns | 2.5x | 2.38x | 1.05x |
| dispatch/raw | 11.7 ns | 84.0 ns | 15.4 ns | 5.5x | 6.06x | 1.33x |
| dispatch/u32 | 20.4 ns | 86.2 ns | 19.4 ns | 4.5x | 3.38x | 0.94x |
| union/number | 26.7 ns | 132.6 ns | 26.1 ns | 5.1x | 3.60x | 0.98x |
| optional/absent | 15.6 ns | 82.1 ns | 14.8 ns | 5.6x | 4.36x | 0.94x |
| property/proto-get | 22.0 ns | 49.5 ns | 23.1 ns | 2.1x | 1.98x | 1.04x |
| callback/reenter | 62.6 ns | 204.8 ns | 87.9 ns | 2.3x | 2.83x | 1.42x |
| resource/unwrap | 77.7 ns | 167.6 ns | 71.1 ns | 2.4x | 1.88x | 0.92x |
| resource/cached-wrap | 53.1 ns | 102.8 ns | 62.2 ns | 1.7x | 1.49x | 1.17x |
| resource/new-wrap | 266.8 ns | 537.5 ns | 319.6 ns | 1.7x | 1.78x | 1.21x |
| native/lifetime/0 | 36.0 ns | 87.0 ns | 52.7 ns | 1.7x | 2.10x | 1.47x |
| struct/pair-roundtrip | 296.3 ns | 604.8 ns | 331.6 ns | 1.8x | 1.94x | 1.12x |
| array/out/64 | 322.5 ns | 1098.6 ns | 459.0 ns | 2.4x | 3.10x | 1.48x |
| buffer/length/16 | 20.2 ns | 99.4 ns | 19.9 ns | 5.0x | 3.70x | 0.99x |
| string/in/ascii/16 | 75.9 ns | 133.8 ns | 57.2 ns | 2.3x | 1.64x | 0.74x |
| gc/allocate-collect/10000 | 3.10 ms | 6.08 ms | 3.79 ms | 1.6x | 1.73x | 1.23x |
| Fast API dispatch/noop | 7.3 ns | 28.4 ns | 18.4 ns | 1.5x | 3.39x | 2.55x |

CPU time per call. "Before" is a --config=benchmark build on main, and "after" is a --config=benchmark --config=cross-lto build with this patch. Both executables ran alternately on the same 4-vCPU x86-64 Linux executor, 3 processes of 5 repetitions each. The table shows the mean of two such runs, which agreed within 15% on every "after" ratio. The C++ column is the C++ time with this patch.

The ratios still depend on compiler flags other than linking. With -march=x86-64-v3 and a lower ThinLTO import limit (-import-instr-limit=50), the median ratio was about 5% higher in two more runs, and the buffer cases were up to 1.5x higher because C++ gains more from AVX2. Only benchmark build files and docs change.

Diff: 418 lines (+313 / -105) across 5 files Reviewer: jasnell Review duration: 3446m
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 418 lines diff across 5 files
0.45
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
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.361
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #8790"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 45.0% (MEDIUM) · Higher = larger blast radius
45.0%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 17.8% · Safe to merge
17.8%