Skip to content

Split Storage trait into Storage and PreprocessorCacheStorage traits - #2607

Closed
xis19 wants to merge 7 commits into
mozilla:mainfrom
xis19:part4
Closed

xis19 wants to merge 7 commits into
mozilla:mainfrom
xis19:part4

Conversation

@xis19

@xis19 xis19 commented Feb 10, 2026 •

Copy link
Copy Markdown
Contributor

This is a series of PRs that

  • Extracts PreprocessorCache from DiskCache.
  • Cleanup some existing code

This is the Part 4. The previous part is #2604.

See #2571 and #2481 for more details.

In this patch, the crate::cache::Storage trait is split into the Storage
and PreprocessorCacheStorage traits, with the implementations stored in
storage.rs and preprocessor_cache.rs, respectively.

The configuration for the preprocessor cache is moved from
DiskCacheConfig to a more general location, CacheConfigs. The config for
the preprocessor cache is moved from

[cache.disk.preprocessor_cache_mode]

to

[cache.preprocessor]

and all original keys are available. In addition, 3 keys are introduced

max_size

is the maximum size for the preprocessor cache.

rw_mode

defines the preprocessor cache as ReadWrite or ReadOnly.

dir

specifies the location of the preprocessor cache. If not specified, the
path to the disk cache will be used.

This allows other storage, e.g., S3, which does not support random
read/write, to also benefit from the preprocessor cache. In the build
environment, one can store the generated object file in a shared object
storage system and put the preprocessor hash locally. This should help
accelerate the whole build process.
@codecov-commenter

codecov-commenter commented Feb 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.81119% with 48 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.49%. Comparing base (df3dda6) to head (a546e70).
⚠️ Report is 117 commits behind head on main.

Files with missing lines Patch % Lines
src/server.rs 63.63% 24 Missing ⚠️
src/compiler/gcc.rs 75.00% 5 Missing ⚠️
src/cache/preprocessor_cache.rs 91.66% 4 Missing ⚠️
src/cache/storage.rs 50.00% 3 Missing ⚠️
src/compiler/compiler.rs 97.11% 3 Missing ⚠️
src/compiler/msvc.rs 78.57% 3 Missing ⚠️
src/config.rs 93.61% 3 Missing ⚠️
src/test/mock_storage.rs 33.33% 2 Missing ⚠️
src/compiler/c.rs 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2607      +/-   ##
==========================================
+ Coverage   72.74%   73.49%   +0.75%     
==========================================
  Files          68       71       +3     
  Lines       36985    37513     +528     
==========================================
+ Hits        26903    27571     +668     
+ Misses      10082     9942     -140     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@xis19

xis19 commented Mar 24, 2026

Copy link
Copy Markdown
Contributor Author

Hello, is there any reviewer updates on this?

@xis19

xis19 commented Apr 1, 2026

Copy link
Copy Markdown
Contributor Author

FYI: I have deployed my version of the code to our internal build cluster, and it seems local preprocessor cache + S3 object file storage works properly.

Comment thread docs/Configuration.md

# See the local docs on more explanations about this mode
[cache.disk.preprocessor_cache_mode]
[cache.preprocessor_cache_mode]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

the field in CacheConfigs is preprocessor, so [cache.preprocessor_cache_mode] will be rejected by deny_unknown_fields.
also, existing [cache.disk.preprocessor_cache_mode] configs will now fail to parse. could we keep accepting it, or at least mention the breaking change?

key: &str,
preprocessor_cache_entry: PreprocessorCacheEntry,
) -> Result<()> {
if self.config.rw_mode == CacheModeConfig::ReadOnly {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

before, a read-only disk cache (SCCACHE_LOCAL_RW_MODE=READ_ONLY, or ReadOnlyStorage) also blocked preprocessor writes.
now only config.rw_mode is checked. is this intended?
please add a test

Some(ref cache) => {
assert!(self.config.use_preprocessor_cache_mode);
let key = normalize_key(key);
info!("PreprocessorCache: put_preprocessor_cache_entry({})", key);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

info! on every put is too noisy, please use debug/trace.
also, the two assert! above could panic the server. do we need them?

Comment thread src/compiler/compiler.rs
CacheMode::ReadWrite,
vec![],
);
let preprocessor_cache_storage = if preprocessor_cache_mode {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

both branches are the same except for the bool, and this block is copied 5 times.
could be use_preprocessor_cache_mode: preprocessor_cache_mode in a small helper, no?

Comment thread src/config.rs
Self {
use_preprocessor_cache_mode: false,
file_stat_matches: false,
file_stat_matches: true,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this is unrelated to the split, and the docs still say false.
please move it to a separate PR

Comment thread src/config.rs

(cache_type, fallback)
if preprocessor_config.dir.is_none() {
preprocessor_config.dir = Some(fallback.dir.join("preprocessor"));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

PreprocessorCache::new also appends preprocessor to the dir, so the cache ends up in <dir>/preprocessor/preprocessor.
existing preprocessor caches are lost on upgrade, no?

Comment thread src/config.rs
.or_else(|| cos.map(CacheType::COS));

let fallback = disk.unwrap_or_default();
let mut preprocessor_config = preprocessor.unwrap_or_default();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

unwrap_or_default() gives use_preprocessor_cache_mode: false.
before, the disk default used PreprocessorCacheModeConfig::activated(), so this silently disables preprocessor cache mode for everyone who doesn't set it.
the docs still say true by default.

Comment thread src/config.rs

// ======= Preprocessor cache =======
let preprocessor_mode_config =
bool_from_env_var("SCCACHE_DIRECT")?.map(|value| PreprocessorCacheModeConfig {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

setting SCCACHE_DIRECT now replaces the whole [cache.preprocessor] section from the file (dir, max_size, rw_mode...) with defaults, no?

@sylvestre

Copy link
Copy Markdown
Collaborator

The refactor direction looks fine, and CI is green. But the PR changes behaviour without saying so. Preprocessor cache mode becomes off by default (it used to be activated() through the DiskCacheConfig default). The on-disk path becomes <dir>/preprocessor/preprocessor. Existing [cache.disk.preprocessor_cache_mode] configs are now rejected by deny_unknown_fields, and the documented [cache.preprocessor_cache_mode] key doesn't parse at all. It also bundles unrelated changes: the file_stat_matches default flip and the clippy lint that is already on main. The tests copy the same if/else block 5 times.

@sylvestre

Copy link
Copy Markdown
Collaborator

this one has been stuck for a while without an update, closing it for now. feel free to reopen if you get back to it, thanks

@sylvestre sylvestre closed this Nov 18, 2026
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.

4 participants