← Back to Pull requests

Make the Rust MemoryCache's read() as cheap as C++ #8804

Closed
unknown closed this pull request without merging on Nov 24, 2026 04:09 UTC
View on GitHub
unknown unknown commented on Nov 22, 2026 05:05 UTC
Author

The Rust MemoryCache follows the promise read() returns, as C++ JSG follows a promise that a method returns, but it does that with then() and an identity callback. Each call allocates a Wrappable for the reaction's data, creates two functions and registers a rejection reaction. C++ makes one function with no data and passes it to Then() alone. That made read() 1.4-2.0x slower than the C++ MemoryCache.

In this patch Rust JSG gets Local<Promise>::pass_through(), which follows a promise the way C++ does, and read() uses it. It settles after the same number of microtasks, which settlesAfterAsManyMicrotasksAsCpp in memory-cache-test.js checks for both caches, so JavaScript sees no change. The Rust MemoryCache is behind the RUST_MEMORY_CACHE autogate, so there is no compat flag. A new jsg-test checks that pass_through() settles one microtask after the promise, with the same value or reason.

The first commit adds the benchmarks in src/bench/memory-cache (a C++ and a Rust config), which the numbers below come from. The C++ and Rust configs were run alternately in one action on the same bazelflare executor, in a --config=benchmark --config=cross-lto build. Each number is the median of 8 rounds.

| case | C++ | Rust before | Rust after | Rust before → after |
|---|---|---|---|---|
| read hit, number | 1567 ns | 2603 ns | 1296 ns | 2.0x |
| read hit with fallback, number | 1623 ns | 2470 ns | 1232 ns | 2.0x |
| read hit, object | 2395 ns | 3424 ns | 2138 ns | 1.6x |
| read hit with fallback, object | 2577 ns | 3559 ns | 2177 ns | 1.6x |
| read miss | 1202 ns | 2279 ns | 1023 ns | 2.2x |
| read miss, fallback caches a number | 10416 ns | 12575 ns | 10940 ns | 1.13x |
| read miss, fallback caches an object | 11272 ns | 14111 ns | 12718 ns | 1.13x |

delete() doesn't change.

Diff: 225 lines (+168 / -57) across 2 files Reviewer: jasnell Review duration: 2823m
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.37) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.37 · 225 lines diff across 2 files
0.37
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%
56%
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.324
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #8804"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 56.8% 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: 36.9% (MEDIUM) · Higher = larger blast radius
36.9%
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: 56.8% · Lower = rushed or shallow review
56.8%
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: 16.0% · Safe to merge
16.0%