rust icon indicating copy to clipboard operation
rust copied to clipboard

Create the previous dep graph index on a background thread

Open Zoxc opened this issue 2 years ago • 13 comments

This changes SerializedDepGraph.index to be computed on-demand per dep kind. This means we can immediately start using queries without waiting for the entire index to be constructed. Additionally a background thread is started which computes the entire index, effectively off-loading most of the index construction to the background thread.

BenchmarkBeforeAfterBeforeAfter
TimeTime%MemoryMemory%
🟣 clap:check:unchanged0.4259s0.4225s -0.79%89.65 MiB90.08 MiB 0.48%
🟣 hyper:check:unchanged0.1425s0.1417s -0.53%47.85 MiB47.91 MiB 0.13%
🟣 regex:check:unchanged0.3188s0.3157s -0.97%71.09 MiB71.58 MiB 0.69%
🟣 syn:check:unchanged0.5895s0.5813s💚 -1.38%101.68 MiB102.15 MiB 0.47%
🟣 syntex_syntax:check:unchanged1.4392s1.4361s -0.22%200.62 MiB201.68 MiB 0.53%
Total2.9158s2.8974s -0.63%510.89 MiB513.40 MiB 0.49%
Summary1.0000s0.9922s -0.78%1 byte1.00 bytes 0.46%
BenchmarkBeforeAfterBeforeAfter
TimeTime%MemoryMemory%
🟠 clap:debug:unchanged1.0753s1.0684s -0.64%142.80 MiB142.72 MiB -0.05%
🟠 hyper:debug:unchanged0.2857s0.2847s -0.35%63.06 MiB63.15 MiB 0.13%
🟠 regex:debug:unchanged0.7703s0.7633s -0.90%108.76 MiB109.03 MiB 0.25%
🟠 syn:debug:unchanged1.0596s1.0531s -0.62%142.08 MiB142.18 MiB 0.07%
🟠 syntex_syntax:debug:unchanged2.7530s2.7274s -0.93%308.92 MiB308.63 MiB -0.09%
Total5.9438s5.8969s -0.79%765.62 MiB765.71 MiB 0.01%
Summary1.0000s0.9931s -0.69%1 byte1.00 bytes 0.06%

r? @cjgillot

Zoxc avatar Oct 03 '23 09:10 Zoxc

In a typical compilation, when happens the first use of this reciprocal index? I'm tempted to say very early, as the first query to be invoked needs it. In which cases is this beneficial?

cjgillot avatar Oct 03 '23 17:10 cjgillot

In a typical compilation, when happens the first use of this reciprocal index? I'm tempted to say very early, as the first query to be invoked needs it.

It will end up calling setup_index, which constructs the index for only that query kind. It's beneficial if we don't use too many query kinds (around 23) before the background thread sets them all.

Zoxc avatar Oct 07 '23 06:10 Zoxc

:umbrella: The latest upstream changes (presumably #118900) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar Dec 13 '23 07:12 bors

Hi @cjgillot, I think this is ready for another round of review as all of the discussion threads have replies from @Zoxc. Thanks!

wesleywiser avatar Dec 14 '23 16:12 wesleywiser

The job x86_64-gnu-llvm-16 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
Built container sha256:9c3c93a371e5aed5c18185b24f130d95d5140dbd72a9b325e7b6b49e521a4faa
Looks like docker image is the same as before, not uploading
https://ci-caches.rust-lang.org/docker/7ebc15c01a233894034d277c8cce4e949f4e7791f66b4727c8fb6e058a0b8171d6152e1441d677cef0653843ceeee469c097b8699b2bb74249e674f6aa1a8813
sha256:9c3c93a371e5aed5c18185b24f130d95d5140dbd72a9b325e7b6b49e521a4faa
Setting extra environment values for docker:  --env ENABLE_GCC_CODEGEN=1 --env GCC_EXEC_PREFIX=/usr/lib/gcc/
[CI_JOB_NAME=x86_64-gnu-llvm-16]
##[group]Clock drift check
  local time: Fri Jan 19 06:14:56 UTC 2024
  network time: Fri, 19 Jan 2024 06:14:57 GMT
  network time: Fri, 19 Jan 2024 06:14:57 GMT
##[endgroup]
sccache: Starting the server...
##[group]Configure the build
configure: processing command line
configure: 
configure: build.configure-args := ['--build=x86_64-unknown-linux-gnu', '--llvm-root=/usr/lib/llvm-16', '--enable-llvm-link-shared', '--set', 'rust.thin-lto-import-instr-limit=10', '--set', 'change-id=99999999', '--enable-verbose-configure', '--enable-sccache', '--disable-manage-submodules', '--enable-locked-deps', '--enable-cargo-native-static', '--set', 'rust.codegen-units-std=1', '--set', 'dist.compression-profile=balanced', '--dist-compression-formats=xz', '--set', 'build.optimized-compiler-builtins', '--disable-dist-src', '--release-channel=nightly', '--enable-debug-assertions', '--enable-overflow-checks', '--enable-llvm-assertions', '--set', 'rust.verify-llvm-ir', '--set', 'rust.codegen-backends=llvm,cranelift,gcc', '--set', 'llvm.static-libstdcpp', '--enable-new-symbol-mangling']
configure: target.x86_64-unknown-linux-gnu.llvm-config := /usr/lib/llvm-16/bin/llvm-config
configure: llvm.link-shared     := True
configure: rust.thin-lto-import-instr-limit := 10
configure: change-id            := 99999999
---
   Compiling rustc_parse v0.0.0 (/checkout/compiler/rustc_parse)
error: unused variable: `token`
   --> compiler/rustc_query_system/src/dep_graph/serialized.rs:222:27
    |
222 |                 if let Ok(token) = client.acquire() {
    |                           ^^^^^ help: if this is intentional, prefix it with an underscore: `_token`
    = note: `-D unused-variables` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(unused_variables)]`

error: method `spawn_prefetch_thread` is never used
error: method `spawn_prefetch_thread` is never used
   --> compiler/rustc_query_system/src/dep_graph/serialized.rs:218:8
    |
119 | impl SerializedDepGraph {
    | ----------------------- method in this implementation
...
218 |     fn spawn_prefetch_thread(self: &Arc<Self>) {
    |
    = note: `-D dead-code` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(dead_code)]`

rust-log-analyzer avatar Jan 19 '24 06:01 rust-log-analyzer

Probably should do a perf run here as the result in https://github.com/rust-lang/rust/pull/122070 was more mixed than expected.

Zoxc avatar Mar 10 '24 08:03 Zoxc

@bors try @rust-timer queue

cjgillot avatar Mar 10 '24 13:03 cjgillot

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

rust-timer avatar Mar 10 '24 13:03 rust-timer

:hourglass: Trying commit 1b9f6d85a9fe1a08ad2adbd5eb3cfe0af771f2db with merge fa1beb3d6a488d654692efb29b4b14c08b15a554...

bors avatar Mar 10 '24 13:03 bors

:sunny: Try build successful - checks-actions Build commit: fa1beb3d6a488d654692efb29b4b14c08b15a554 (fa1beb3d6a488d654692efb29b4b14c08b15a554)

bors avatar Mar 10 '24 14:03 bors

:sunny: Try build successful - checks-actions Build commit: fa1beb3d6a488d654692efb29b4b14c08b15a554 (fa1beb3d6a488d654692efb29b4b14c08b15a554)

bors avatar Mar 10 '24 14:03 bors

Queued fa1beb3d6a488d654692efb29b4b14c08b15a554 with parent 3521a2f2f317cb978063842485c7d1bc86ec82b6, future comparison URL. There is currently 1 preceding artifact in the queue. It will probably take at least ~1.7 hours until the benchmark run finishes.

rust-timer avatar Mar 10 '24 14:03 rust-timer

Finished benchmarking commit (fa1beb3d6a488d654692efb29b4b14c08b15a554): comparison URL.

Overall result: ❌ regressions - ACTION NEEDED

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never @rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
2.0% [0.3%, 3.4%] 103
Regressions ❌
(secondary)
1.5% [0.6%, 2.3%] 27
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.0% [0.3%, 3.4%] 103

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.3% [1.6%, 3.1%] 3
Improvements ✅
(primary)
-1.1% [-1.1%, -1.1%] 1
Improvements ✅
(secondary)
-3.3% [-6.4%, -1.3%] 54
All ❌✅ (primary) -1.1% [-1.1%, -1.1%] 1

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
1.7% [1.0%, 2.4%] 14
Regressions ❌
(secondary)
3.0% [2.2%, 3.6%] 4
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.7% [1.0%, 2.4%] 14

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 647.634s -> 647.342s (-0.05%) Artifact size: 310.02 MiB -> 309.93 MiB (-0.03%)

rust-timer avatar Mar 10 '24 16:03 rust-timer

That's quite an odd performance result. It seem to have large wall time regressions which don't show up in the self profiling results nor can I reproduce them locally.

Zoxc avatar Mar 11 '24 01:03 Zoxc

:umbrella: The latest upstream changes (presumably #122070) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar Apr 05 '24 13:04 bors

I think this is waiting on a comment on the perf run? @Zoxc Do you need some directions? Also a rebase when you have a chance. Thanks!

@rustbot author

apiraino avatar Jun 20 '24 13:06 apiraino