Skip to content

Conversation

@DaniPopes
Copy link

Currently, sccache invokes rustc twice for generating the hash key: once for the inputs and env-deps (--emit dep-info), and another time for the output file names (--print file-names).
However, the latter is invoked only after the former finishes. There is no reason for this dependency.

Run get_compiler_outputs concurrently with the other rustc and hashing tasks in RustHasher::generate_hash_key.

I initially thought that these two invocations could be merged together, but --print stop compilation before the --emit is evaluated, so I went with the simpler approach of just running them at the same time.

Currently, `sccache` invokes `rustc` twice for generating the hash key:
once for the inputs and env-deps (`--emit dep-info`), and another time
for the output file names (`--print file-names`).
However, the latter is invoked only after the former finishes. There is
no reason for this dependency.

Run `get_compiler_outputs` concurrently with the other `rustc` and
hashing tasks in `RustHasher::generate_hash_key`.

I initially thought that these two invocations could be merged together,
but `--print` stop compilation before the `--emit` is evaluated, so I
went with the simpler approach of just running them at the same time.
@sylvestre
Copy link
Collaborator

nice
would it be possible to have a test to make sure we don't regress in the future ?
did you evaluate a perf win here?

Thanks

@codecov-commenter
Copy link

codecov-commenter commented Oct 20, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.22%. Comparing base (1e2f32a) to head (6654b9a).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2465   +/-   ##
=======================================
  Coverage   71.22%   71.22%           
=======================================
  Files          64       64           
  Lines       35221    35224    +3     
=======================================
+ Hits        25087    25090    +3     
  Misses      10134    10134           

☔ View full report in Codecov by Sentry.
📢 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.

@DaniPopes
Copy link
Author

would it be possible to have a test to make sure we don't regress in the future ?

I'm not sure how best to add a test here since the behavior is the exact same

did you evaluate a perf win here?

I measured the time reported by the generate_hash_key debug log in a dummy Cargo project importing syn (-j1):

run main-0
[2025-10-21T15:14:26.485Z DEBUG sccache::compiler::compiler] [proc_macro2]: generate_hash_key took 0.019 s
[2025-10-21T15:14:26.587Z DEBUG sccache::compiler::compiler] [unicode_ident]: generate_hash_key took 0.021 s
[2025-10-21T15:14:26.623Z DEBUG sccache::compiler::compiler] [proc_macro2]: generate_hash_key took 0.031 s
[2025-10-21T15:14:26.665Z DEBUG sccache::compiler::compiler] [quote]: generate_hash_key took 0.026 s
[2025-10-21T15:14:26.765Z DEBUG sccache::compiler::compiler] [syn]: generate_hash_key took 0.094 s
run main-1
[2025-10-21T15:14:27.156Z DEBUG sccache::compiler::compiler] [proc_macro2]: generate_hash_key took 0.018 s
[2025-10-21T15:14:27.182Z DEBUG sccache::compiler::compiler] [unicode_ident]: generate_hash_key took 0.020 s
[2025-10-21T15:14:27.302Z DEBUG sccache::compiler::compiler] [proc_macro2]: generate_hash_key took 0.032 s
[2025-10-21T15:14:27.336Z DEBUG sccache::compiler::compiler] [quote]: generate_hash_key took 0.025 s
[2025-10-21T15:14:27.429Z DEBUG sccache::compiler::compiler] [syn]: generate_hash_key took 0.087 s
run main-2
[2025-10-21T15:14:27.833Z DEBUG sccache::compiler::compiler] [proc_macro2]: generate_hash_key took 0.019 s
[2025-10-21T15:14:27.935Z DEBUG sccache::compiler::compiler] [unicode_ident]: generate_hash_key took 0.021 s
[2025-10-21T15:14:27.972Z DEBUG sccache::compiler::compiler] [proc_macro2]: generate_hash_key took 0.032 s
[2025-10-21T15:14:28.014Z DEBUG sccache::compiler::compiler] [quote]: generate_hash_key took 0.026 s
[2025-10-21T15:14:28.107Z DEBUG sccache::compiler::compiler] [syn]: generate_hash_key took 0.087 s
run main-3
[2025-10-21T15:14:28.497Z DEBUG sccache::compiler::compiler] [proc_macro2]: generate_hash_key took 0.018 s
[2025-10-21T15:14:28.595Z DEBUG sccache::compiler::compiler] [unicode_ident]: generate_hash_key took 0.020 s
[2025-10-21T15:14:28.629Z DEBUG sccache::compiler::compiler] [proc_macro2]: generate_hash_key took 0.029 s
[2025-10-21T15:14:28.667Z DEBUG sccache::compiler::compiler] [quote]: generate_hash_key took 0.024 s
[2025-10-21T15:14:28.761Z DEBUG sccache::compiler::compiler] [syn]: generate_hash_key took 0.087 s
run main-4
[2025-10-21T15:14:29.156Z DEBUG sccache::compiler::compiler] [proc_macro2]: generate_hash_key took 0.018 s
[2025-10-21T15:14:29.258Z DEBUG sccache::compiler::compiler] [unicode_ident]: generate_hash_key took 0.020 s
[2025-10-21T15:14:29.292Z DEBUG sccache::compiler::compiler] [proc_macro2]: generate_hash_key took 0.029 s
[2025-10-21T15:14:29.331Z DEBUG sccache::compiler::compiler] [quote]: generate_hash_key took 0.024 s
[2025-10-21T15:14:29.428Z DEBUG sccache::compiler::compiler] [syn]: generate_hash_key took 0.090 s
run main-5
[2025-10-21T15:14:29.820Z DEBUG sccache::compiler::compiler] [proc_macro2]: generate_hash_key took 0.018 s
[2025-10-21T15:14:29.846Z DEBUG sccache::compiler::compiler] [unicode_ident]: generate_hash_key took 0.019 s
[2025-10-21T15:14:29.961Z DEBUG sccache::compiler::compiler] [proc_macro2]: generate_hash_key took 0.031 s
[2025-10-21T15:14:29.994Z DEBUG sccache::compiler::compiler] [quote]: generate_hash_key took 0.024 s
[2025-10-21T15:14:30.087Z DEBUG sccache::compiler::compiler] [syn]: generate_hash_key took 0.086 s
run patch-0
[2025-10-21T15:14:30.478Z DEBUG sccache::compiler::compiler] [proc_macro2]: generate_hash_key took 0.011 s
[2025-10-21T15:14:30.497Z DEBUG sccache::compiler::compiler] [unicode_ident]: generate_hash_key took 0.012 s
[2025-10-21T15:14:30.601Z DEBUG sccache::compiler::compiler] [proc_macro2]: generate_hash_key took 0.023 s
[2025-10-21T15:14:30.626Z DEBUG sccache::compiler::compiler] [quote]: generate_hash_key took 0.017 s
[2025-10-21T15:14:30.708Z DEBUG sccache::compiler::compiler] [syn]: generate_hash_key took 0.076 s
run patch-1
[2025-10-21T15:14:31.085Z DEBUG sccache::compiler::compiler] [proc_macro2]: generate_hash_key took 0.010 s
[2025-10-21T15:14:31.103Z DEBUG sccache::compiler::compiler] [unicode_ident]: generate_hash_key took 0.012 s
[2025-10-21T15:14:31.208Z DEBUG sccache::compiler::compiler] [proc_macro2]: generate_hash_key took 0.022 s
[2025-10-21T15:14:31.233Z DEBUG sccache::compiler::compiler] [quote]: generate_hash_key took 0.016 s
[2025-10-21T15:14:31.320Z DEBUG sccache::compiler::compiler] [syn]: generate_hash_key took 0.081 s
run patch-2
[2025-10-21T15:14:31.707Z DEBUG sccache::compiler::compiler] [proc_macro2]: generate_hash_key took 0.011 s
[2025-10-21T15:14:31.725Z DEBUG sccache::compiler::compiler] [unicode_ident]: generate_hash_key took 0.011 s
[2025-10-21T15:14:31.832Z DEBUG sccache::compiler::compiler] [proc_macro2]: generate_hash_key took 0.022 s
[2025-10-21T15:14:31.856Z DEBUG sccache::compiler::compiler] [quote]: generate_hash_key took 0.016 s
[2025-10-21T15:14:31.942Z DEBUG sccache::compiler::compiler] [syn]: generate_hash_key took 0.079 s
run patch-3
[2025-10-21T15:14:32.321Z DEBUG sccache::compiler::compiler] [proc_macro2]: generate_hash_key took 0.011 s
[2025-10-21T15:14:32.340Z DEBUG sccache::compiler::compiler] [unicode_ident]: generate_hash_key took 0.012 s
[2025-10-21T15:14:32.447Z DEBUG sccache::compiler::compiler] [proc_macro2]: generate_hash_key took 0.022 s
[2025-10-21T15:14:32.473Z DEBUG sccache::compiler::compiler] [quote]: generate_hash_key took 0.017 s
[2025-10-21T15:14:32.558Z DEBUG sccache::compiler::compiler] [syn]: generate_hash_key took 0.079 s
run patch-4
[2025-10-21T15:14:32.946Z DEBUG sccache::compiler::compiler] [proc_macro2]: generate_hash_key took 0.011 s
[2025-10-21T15:14:32.966Z DEBUG sccache::compiler::compiler] [unicode_ident]: generate_hash_key took 0.013 s
[2025-10-21T15:14:33.077Z DEBUG sccache::compiler::compiler] [proc_macro2]: generate_hash_key took 0.023 s
[2025-10-21T15:14:33.102Z DEBUG sccache::compiler::compiler] [quote]: generate_hash_key took 0.017 s
[2025-10-21T15:14:33.192Z DEBUG sccache::compiler::compiler] [syn]: generate_hash_key took 0.083 s
run patch-5
[2025-10-21T15:14:33.584Z DEBUG sccache::compiler::compiler] [proc_macro2]: generate_hash_key took 0.011 s
[2025-10-21T15:14:33.604Z DEBUG sccache::compiler::compiler] [unicode_ident]: generate_hash_key took 0.013 s
[2025-10-21T15:14:33.716Z DEBUG sccache::compiler::compiler] [proc_macro2]: generate_hash_key took 0.024 s
[2025-10-21T15:14:33.744Z DEBUG sccache::compiler::compiler] [quote]: generate_hash_key took 0.019 s
[2025-10-21T15:14:33.832Z DEBUG sccache::compiler::compiler] [syn]: generate_hash_key took 0.082 s

Looks about ~5-10ms faster per each generate_hash_key call, which makes sense since that's about the duration of the second compiler call.

However, I couldn't notice a difference in the final walltime of a cargo build. I think it's within noise range, or might be bottlenecked by something else..

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