Skip to content

perf(cache): share one flight map with amortized pruning - #2932

Merged
thiras merged 3 commits into
mainfrom
fix/2868-flight-map-helper
Nov 22, 2026
Merged

thiras merged 3 commits into
mainfrom
fix/2868-flight-map-helper

Conversation

@yigitdot

@yigitdot yigitdot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2868

Three copies of one pattern, a Weak map of per-key values that vanish when the last holder drops, become one generic decdn_cache::Flights<K, V>.

  • Amortized pruning everywhere. CacheEngine::outboard_flight and CacheEngine::size_proof_flight scanned the whole map under a std mutex on every miss (O(n²) for n concurrent cold misses). Flights prunes only when the map reaches prune_at, then sets it to max(2 * live, 16): amortized O(1) per insert, as the gateway's manifest fill map already did.
  • One helper. Gateway::manifest_flight and both engine sites use Flights. ManifestFills and FLIGHT_PRUNE_FLOOR are gone.
  • Where it lives. decdn-cache: cli already depends on it, so no crate edge changes and check_crate_edges.py is untouched. The value type is generic (V: Default), so the gateway's Flight and the engine's tokio::sync::Mutex<()> both fit.

size_proof_flight is not named in the issue, but it is the same O(n) prune, so it moves too.

Test plan

  • New flights unit tests: live-entry reuse, replacement after drop, amortized prune count, live entries survive a prune, a non-mutex value type
  • Gateway fill tests and cache outboard/size-proof tests
  • cargo clippy --workspace --all-targets -- -D warnings, cargo doc gate, check_crate_edges.py

Copilot AI balanced review requested due to automatic review settings November 21, 2026 15:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-code-quality

github-code-quality Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main fb28695 fix/2868-flight-map-... ae93f58 +/-
77% 77% 0%
View coverage of the 6 most impacted files.
File main fb28695 fix/2868-flight-map-... ae93f58 +/-
crates/protocol/src/framing.rs 93% 92% -1%
crates/cli/src/...ands/gateway.rs 80% 80% 0%
crates/client/s...undle/engine.rs 61% 61% 0%
crates/cache/src/engine.rs 91% 91% 0%
crates/node/src...gin/pull_leg.rs 85% 85% 0%
crates/cache/src/flights.rs 0% 88% +88%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated November 22, 2026 00:11 UTC

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread crates/cache/src/flights.rs Resolved
@thiras
thiras enabled auto-merge (squash) November 22, 2026 00:06
@thiras
thiras merged commit ea63ab6 into main Nov 22, 2026
37 checks passed
@thiras
thiras deleted the fix/2868-flight-map-helper branch November 22, 2026 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flight maps: amortize pruning and share one helper

3 participants