Skip to content

client: support in-process compilation without daemon IPC - #2955

Open
rebroad wants to merge 2 commits into
mozilla:mainfrom
rebroad:pr/in-process-sandbox-cache
Open

rebroad wants to merge 2 commits into
mozilla:mainfrom
rebroad:pr/in-process-sandbox-cache

Conversation

@rebroad

@rebroad rebroad commented Oct 26, 2026 •

Copy link
Copy Markdown

Sandbox policies can deny local IPC while allowing access to cache storage. This adds SCCACHE_IN_PROCESS=1 so each compiler wrapper runs the compile pipeline without starting or contacting the daemon. Disk cache operations use a cross-process lock, and in-process statistics are shared across wrappers. Distributed compilation remains disabled in this mode.

@rebroad
rebroad force-pushed the pr/in-process-sandbox-cache branch from 65fc778 to 5a054f4 Compare October 26, 2026 13:57
@rebroad

rebroad commented Oct 28, 2026

Copy link
Copy Markdown
Author

The current PR head (1b8ed87eed4c45dc2292eab1fe8bb9e6f7a7bd31) passed the ci, integration-tests, and Benchmarks workflows on my fork, rebroad/sccache: ci, integration-tests, Benchmarks. These runs used the same commit as this PR head.

@rebroad
rebroad marked this pull request as ready for review October 28, 2026 08:41
@codecov-commenter

codecov-commenter commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.14482% with 127 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.62%. Comparing base (dac6c80) to head (1b8ed87).

Files with missing lines Patch % Lines
src/cache/disk.rs 76.92% 57 Missing ⚠️
src/mock_command.rs 50.87% 28 Missing ⚠️
src/commands.rs 87.27% 14 Missing ⚠️
tests/sccache_rustc.rs 93.50% 10 Missing ⚠️
src/cache/ipc_storage.rs 18.18% 9 Missing ⚠️
src/in_process_stats.rs 80.43% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2955      +/-   ##
==========================================
+ Coverage   78.54%   78.62%   +0.07%     
==========================================
  Files          74       76       +2     
  Lines       44039    44806     +767     
==========================================
+ Hits        34591    35229     +638     
- Misses       9448     9577     +129     

☔ 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.

@sylvestre

Copy link
Copy Markdown
Collaborator

thanks for looking into this!
The main blocker is that every put rebuilds the LRU by walking the whole cache dir under the global lock (see inline). Could you please share some numbers on a real-size cache?

Comment thread src/cache/disk.rs
let file = self
.pool
.spawn_blocking(move || -> Result<Option<File>> {
let _lock = lock_cache_directory(&root)?;

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 same open + set_file_times under the lock is repeated in get, get_raw, get_path and get_preprocessor_cache_entry. could be dedup, no?

Comment thread src/cache/disk.rs
.spawn_blocking(move || {
let _lock = lock_cache_directory(&root)?;
let start = Instant::now();
let mut lru = LruDiskCache::new(&root, max_size)?;

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.

LruDiskCache::new walks the whole cache dir on every put, while holding the global lock.
with a 10G cache, every cache write scans all entries and serializes all the wrappers, no?
could you please share some numbers on a real-size cache?

@sylvestre

Copy link
Copy Markdown
Collaborator

sorry but it needs to be rebased

Comment thread src/cache/ipc_storage.rs
.with_context(|| format!("IpcStorage::get: open {}", path.display()))?;
let file = match std::fs::File::open(&path) {
Ok(file) => file,
// A process-safe disk cache may evict the entry after the daemon

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 daemon never builds a process-safe disk cache, so this seems unrelated to the PR. please move it into a different pr

Comment thread src/commands.rs
let (compile_resp, finished, forwarded_notification) =
runtime.block_on(service.compile_direct(compile, &mut *stderr))?;
let exit_code = if matches!(compile_resp, CompileResponse::UnhandledCompile) {
// Run unsupported compiler invocations directly. In isolated

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 bypasses the command creator and the jobserver, and duplicates the signal handling of handle_compile_result
why not let handle_compile_result run it like the other modes do?

Comment thread src/commands.rs
let (info, cache_mode) = request_stats_with_cache_mode(srv)
.context("failed to get stats from server")?;
(info, Some(cache_mode))
let in_process_mode = env::var("SCCACHE_IN_PROCESS").is_ok_and(|value| value == "1");

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.

please add it to Config like client_side_mode (bool_from_env_var) instead of parsing the env var by hand in 5 places
it also means SCCACHE_IN_PROCESS=true is silently ignored

Comment thread src/commands.rs
// anyways, so we can just return (mostly) empty stats directly.
Err(_) => (empty_server_info(config)?, None),
};
stats.stats += crate::in_process_stats::read(&config.fallback_cache.dir)?;

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.

with ?, a corrupted stats file breaks --show-stats in the default mode too, while add() just resets it.
maybe warn and ignore here as well?

Comment thread src/mock_command.rs
async fn wait(self) -> io::Result<ExitStatus> {
let Child { mut inner, token } = self;
inner.wait().await.inspect(|_ret| {
let result = if std::env::var("SCCACHE_IN_PROCESS").is_ok_and(|value| value == "1") {

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.

we now have three workarounds for the same reaping issue: the 2-worker runtime, std::process for unhandled compiles, and this 10ms polling.
do we need the three of them?
also, mock_command reading SCCACHE_IN_PROCESS directly isn't great, maybe pass it through the creator?

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.

3 participants