Skip to content

flight maps: amortize pruning and share one helper #2868

Closed

Description

@yigitdot

Two follow-ups from the review of #2866, which keys the gateway's manifest fill lock per hash and namespace. Both sit outside that PR's files.

outboard_flights prunes in O(n) per miss

CacheEngine::outboard_flight (crates/cache/src/engine.rs) runs flights.retain(|_, w| w.strong_count() > 0) on every lookup that misses. That scans the whole map under the std mutex each time, so N concurrent cold misses of distinct hashes cost O(N²) work under the lock. #2866 fixes the same pattern in the gateway's manifest_flight: it prunes only when the map reaches prune_at, then sets prune_at = max(2 * live, 16). That makes pruning amortized O(1) and keeps the map within about twice the live fills plus 16. Apply the same change to outboard_flights.

One flight-map helper

manifest_flight (crates/cli/src/commands/gateway.rs) and outboard_flight (crates/cache/src/engine.rs) are copies of one pattern: a Weak map of per-key values whose entries vanish when the last holder drops. A generic Flights<K, V> (lookup-or-insert of an Arc<V>, plus amortized pruning) would remove the copy. Move both sides in one change, so the helper does not ship with a copy left behind.

  • Value type. The helper must be generic over the value, not fixed to Mutex<()>: the gateway's Flight holds a fill counter and a shared failure beside its lock, while the cache engine's holds a bare lock.
  • Crate. Under the crate-edge table, cache does not depend on common, so the helper needs a crate both cli and cache reach. decdn-protocol is the only such leaf that already depends on tokio, but it holds the wire format, so placing a concurrency helper there is a design call; a new leaf crate is the alternative. Either way, update .github/scripts/check_crate_edges.py and the CLAUDE.md dependency paragraph if an edge changes.

Activity

  1. added
    kind:chore
    prio:low
    area:cache
    area:cli
    on Nov 11, 2026
  2. moved this from Backlog to In progress in deCDNon Nov 21, 2026
  3. moved this from In progress to Done in deCDNon Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:cachearea:clikind:choreprio:low

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions