Repository navigation
Description
Summary
In MultiLevelStorage::get(), a cache hit on any level above L0 reads the same object from that level twice: once through get() to build the entry returned to the compiler, and again through get_raw() to obtain bytes for backfilling the faster levels. For remote levels both calls perform a full object read.
The second read is awaited before the hit is returned, so it sits on the compiler's critical path rather than in the spawned backfill tasks.
Code
v0.17.0 (c037e11), src/cache/multilevel.rs L637-L714:
match level.get(key).await { // first read: full object read + CacheRead decode
Ok(Cache::Hit(entry)) => {
// ...
if idx > 0 {
match level.get_raw(key).await { // second read: same object, fetched again
Ok(Some(raw_bytes)) => {
for backfill_idx in 0..idx {
tokio::spawn(/* backfill using bytes from the second read */);
}
}
// ...
}
}
return Ok(Cache::Hit(entry));
}For RemoteStorage both paths call operator.read():
get()—src/cache/cache.rsL231get_raw()—src/cache/cache.rsL338
So with SCCACHE_MULTILEVEL_CHAIN=disk,s3, every L1 hit issues two S3 GETs for the same key, transfers the object twice, and the compiler waits for both.
Suggested fix
Fetch the bytes once and derive both the returned entry and the backfill payload from them — for example call get_raw() first and construct CacheRead::from(io::Cursor::new(bytes)) locally, keeping the current path as a fallback for backends whose get_raw() returns None.
Impact
Request count and transferred bytes for lower-level hits are doubled, and the duplicate fetch is serialized ahead of the compiler result.
I want to be careful not to overstate the wall-clock cost: I found this by reading the source, and the multi-level trial in our CI benchmarks was also running SCCACHE_CLIENT_SIDE=1, which introduced a much larger penalty of its own. So I have not isolated how much of a real build this accounts for, and concurrent requests presumably hide part of it. The redundant fetch itself is unambiguous in the code.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity