Skip to content

bench: measure basedir stripping from compiler arguments - #2838

Open
tcashel wants to merge 1 commit into
mozilla:mainfrom
tcashel:codex/rust-basedirs-benchmark
Open

tcashel wants to merge 1 commit into
mozilla:mainfrom
tcashel:codex/rust-basedirs-benchmark

Conversation

@tcashel

@tcashel tcashel commented Sep 2, 2026 •

Copy link
Copy Markdown

Adds a benchmark for the existing strip_basedirs_from_arg helper. Each iteration strips 100 path arguments with 0, 1, 8, or 32 configured roots; 90% of paths are outside those roots. Fixture assertions verify matching and unchanged outputs before timing.

This PR changes only benches/sccache_bench.rs and applies directly to current upstream. It no longer includes or depends on #2813. It measures the compiler-argument helper already in main, rather than the Rust-specific matcher proposed there.

Formatting, clippy, the locked unit/integration suite, and all four benchmark cases pass on Apple silicon. CUDA cases skip locally. Developed with OpenAI Codex.

@codecov-commenter

codecov-commenter commented Sep 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.23077% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.54%. Comparing base (b45240d) to head (5b48e27).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
src/compiler/rust.rs 99.25% 2 Missing ⚠️
src/util.rs 99.37% 1 Missing ⚠️
tests/sccache_cargo.rs 98.52% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2838      +/-   ##
==========================================
- Coverage   73.71%   72.54%   -1.17%     
==========================================
  Files          72       72              
  Lines       37932    39632    +1700     
==========================================
+ Hits        27963    28753     +790     
- Misses       9969    10879     +910     

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

Comment thread docs/Configuration.md Outdated
* `SCCACHE_ALLOW_CORE_DUMPS` to enable core dumps by the server
* `SCCACHE_CONF` configuration file path
* `SCCACHE_BASEDIRS` base directory (or directories) to strip from paths for cache key computation. This is similar to ccache's `CCACHE_BASEDIR` and enables cache hits across different absolute paths when compiling the same source code. Multiple directories can be separated by `;` on Windows hosts and by `:` on any other operating system. When multiple directories are specified, the longest matching prefix is used. Path matching is **case-insensitive** on Windows and **case-sensitive** on other operating systems. Environment variable takes precedence over file configuration. Only absolute paths are supported; relative paths will cause an error and prevent the server from start.
* `SCCACHE_BASEDIRS` base directory (or directories) to strip from paths for cache key computation. This is similar to ccache's `CCACHE_BASEDIR` and enables cache hits across different absolute paths when compiling the same source code. Multiple directories can be separated by `;` on Windows hosts and by `:` on any other operating system. When multiple directories are specified, the longest matching prefix is used. Path matching is **case-insensitive** on Windows and **case-sensitive** on other operating systems. For Rust, sccache normalizes matching absolute source arguments, the source side of `--remap-path-prefix`, Cargo path variables, tracked environment dependency values that are absolute paths, and the current working directory. Environment variable takes precedence over file configuration. Only absolute paths are supported; relative paths will cause an error and prevent the server from starting. This setting changes cache keys but does not rewrite paths embedded in artifacts; a Rust artifact can retain an absolute path from the compilation that populated the cache.

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.

sorry but i just would like the benchmark change in this PR

Comment thread docs/Rust.md Outdated
* Procedural macros that read files from the filesystem may not be cached properly.
* `rustc`'s incremental compilation needs to be disabled. See [The Cargo Book](https://doc.rust-lang.org/cargo/reference/profiles.html#incremental)
* Crates that invoke the system linker cannot be cached. Examples are `bin`, `dylib`, `cdylib`, and `proc-macro` crates.
* `SCCACHE_BASEDIRS` normalizes matching paths in cache-key inputs, but it does not rewrite paths embedded in artifacts. For example, a crate that uses `env!("CARGO_MANIFEST_DIR")` can retain the path from the compilation that populated a shared cache entry.

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.

same

@tcashel
tcashel force-pushed the codex/rust-basedirs-benchmark branch from 5b48e27 to c9b3c45 Compare September 17, 2026 19:13
@tcashel tcashel changed the title bench: measure Rust basedir path stripping bench: measure basedir stripping from compiler arguments Sep 17, 2026
Comment thread benches/sccache_bench.rs
bencher.bench(|| black_box(strip_basedirs(black_box(&output), black_box(&basedirs))));
}

/// Most dependency paths fall outside the configured checkout roots.

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 0 case returns immediately in the helper, so it only measures the loop —-worth keeping?

Comment thread benches/sccache_bench.rs

/// Most dependency paths fall outside the configured checkout roots.
#[divan::bench(args = [0, 1, 8, 32])]
fn strip_basedirs_from_arg_mostly_unmatched(bencher: Bencher, root_count: usize) {

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.

all the inputs here are bare paths, but this helper is about compiler arguments — could you please bench -I/path, -ffile-prefix-map=/path=/x too? that's where pathname_positions does the work.

Comment thread benches/sccache_bench.rs
.map(|i| format!("/workspaces/project/checkouts/worktree-{i:02}/").into_bytes())
.collect();
let paths: Vec<Vec<u8>> = (0..100)
.map(|i| {

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.

why 7? please document or just use i / 10

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