Repository navigation
perf(cache): share one flight map with amortized pruning - #2932
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
Code coverage overviewLanguages: Rust Rust / code-coverage/cargo-llvm-cov
View coverage of the 6 most impacted files.
ℹ️ Calculations represent line coverage. Results may change as calculations are updated. Updated |
There was a problem hiding this comment.
🟡 Changes recommended
Pruning leaves the HashMap’s large capacity intact after bursts, causing frequent full-capacity scans under the shared mutex and invalidating the amortized O(1) claim; capacity shrinking and a capacity-checking regression test are needed.
1 open issue
Review effort: Balanced

Closes #2868
Three copies of one pattern, a
Weakmap of per-key values that vanish when the last holder drops, become one genericdecdn_cache::Flights<K, V>.CacheEngine::outboard_flightandCacheEngine::size_proof_flightscanned the whole map under a std mutex on every miss (O(n²) for n concurrent cold misses).Flightsprunes only when the map reachesprune_at, then sets it tomax(2 * live, 16): amortized O(1) per insert, as the gateway's manifest fill map already did.Gateway::manifest_flightand both engine sites useFlights.ManifestFillsandFLIGHT_PRUNE_FLOORare gone.decdn-cache:clialready depends on it, so no crate edge changes andcheck_crate_edges.pyis untouched. The value type is generic (V: Default), so the gateway'sFlightand the engine'stokio::sync::Mutex<()>both fit.size_proof_flightis not named in the issue, but it is the same O(n) prune, so it moves too.Test plan
flightsunit tests: live-entry reuse, replacement after drop, amortized prune count, live entries survive a prune, a non-mutex value typecargo clippy --workspace --all-targets -- -D warnings,cargo docgate,check_crate_edges.py