Repository navigation
Description
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'sFlightholds 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,
cachedoes not depend oncommon, so the helper needs a crate bothcliandcachereach.decdn-protocolis 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.pyand the CLAUDE.md dependency paragraph if an edge changes.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Projects
- StatusShow more project fieldsDone
Activity