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

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.75%. Comparing base (75ef6fa) to head (58e6a5e).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2838   +/-   ##
=======================================
  Coverage   72.74%   72.75%           
=======================================
  Files          77       77           
  Lines       44680    44680           
=======================================
+ Hits        32504    32508    +4     
+ Misses      12176    12172    -4     

☔ 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

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.

By the way, are you sure it's only Rust artifacts? AFAIK, sccache is not patching compiler outputs to fake the circumstances under which they were compiled in any language.

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

@sylvestre
sylvestre force-pushed the codex/rust-basedirs-benchmark branch from c9b3c45 to 67862f4 Compare November 9, 2026 01:58
@codspeed

codspeed Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will regress 2 benchmarks

2 warnings

⚠️ 1 benchmark is dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚠️ 4 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚡ 2 improved benchmarks
❌ 2 regressed benchmarks
✅ 58 untouched benchmarks
🆕 8 new benchmarks
⏩ 6 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ CPU Simulation build_workflow_rebuild 14.7 ms 16.8 ms -12.41%
❌ CPU Simulation build_workflow_incremental 18.9 ms 20.9 ms -9.7%
⚡ CPU Simulation decompression_low_ratio 3.3 ms 2.1 ms +53.36%
⚡ CPU Simulation decompression_high_ratio 3.4 ms 2.3 ms +49.66%
🆕 CPU Simulation strip_basedirs_from_arg_mostly_unmatched[0] N/A 8.5 µs N/A
🆕 CPU Simulation strip_basedirs_from_arg_mostly_unmatched[1] N/A 65.7 µs N/A
🆕 CPU Simulation strip_basedirs_from_arg_mostly_unmatched[32] N/A 259.7 µs N/A
🆕 CPU Simulation strip_basedirs_from_arg_mostly_unmatched[8] N/A 113.9 µs N/A
🆕 Memory strip_basedirs_from_arg_mostly_unmatched[0] N/A 0 B N/A
🆕 Memory strip_basedirs_from_arg_mostly_unmatched[1] N/A 92 B N/A
🆕 Memory strip_basedirs_from_arg_mostly_unmatched[32] N/A 340 B N/A
🆕 Memory strip_basedirs_from_arg_mostly_unmatched[8] N/A 148 B N/A

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing tcashel:codex/rust-basedirs-benchmark (58e6a5e) with main (75ef6fa)

Open in CodSpeed

Footnotes

  1. 6 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@sylvestre

Copy link
Copy Markdown
Collaborator

hi, any news on the 5 comments above? thanks

@sylvestre
sylvestre force-pushed the codex/rust-basedirs-benchmark branch from 67862f4 to 58e6a5e Compare December 2, 2026 21:21
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