pub struct BlockCache { /* private fields */ }Expand description
Verified segment blocks, evicted least recently used first once their total size passes the budget.
A build’s resolver threads read the same segments at once, and one lock for every hit made each hit wait for all the others (12 threads: 4.9 us per hit, against 0.1 us for one thread). So the cache is split into shards by block, each with its own lock, its own share of the budget and its own use order, and a hit takes only its shard’s read lock: it stamps the block’s last use atomically and leaves the use order alone. The order catches up at eviction, which moves a block it finds used since it was listed instead of evicting it. Eviction is therefore least recently used within a shard; a small cache keeps one shard, so its order is exact.
Implementations§
Source§impl BlockCache
impl BlockCache
Sourcepub fn new(budget_bytes: usize) -> Self
pub fn new(budget_bytes: usize) -> Self
A cache holding at most budget_bytes of block data.
§Panics
If the budget is smaller than one block: such a cache could not hold the block a read is waiting for.
Sourcepub fn set_budget(&self, bytes: usize)
pub fn set_budget(&self, bytes: usize)
Resize without invalidating blocks readers already hold. Each shard keeps its identity; a shrink releases at most 64 entries per lock hold. The budget must still allow at least one block per existing shard.
pub fn stats(&self) -> CacheStats
Sourcepub fn memory_bytes(&self) -> Option<usize>
pub fn memory_bytes(&self) -> Option<usize>
The bytes the cache holds in memory, measured as crate::heap
describes: every cached block in its shared allocation, and the two
tables that find a block and order blocks by use. None while
another thread holds the cache’s lock: the memory census never waits
for it.