Skip to content

Garbage-collect old incremental compilation sessions - #162240

Merged
rust-bors[bot] merged 3 commits into
rust-lang:mainfrom
charliermarsh:charlie/incremental-session-gc
Sep 14, 2026
Merged

rust-bors[bot] merged 3 commits into
rust-lang:mainfrom
charliermarsh:charlie/incremental-session-gc

Conversation

@charliermarsh

@charliermarsh charliermarsh commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

View all comments

Summary

rustc cleans up old incremental-cache snapshots twice during a compilation: once at startup (after loading the previous cache), and then again after finishing and finalizing the new cache.

In #147821, we started skipping the current session during cleanup. But that means we're also skipping cleanup after the session has finished, so we're keeping both the previous and the completed snapshot on disk. (The snapshots don't accumulate indefinitely -- the "extra" snapshot gets removed when the next compilation starts, but that compilation then leaves another snapshot behind when it finishes.)

This PR modifies the logic to skip the current session while it is still active, but remove it once finalized.

Testing it locally for Ruff and uv, the target directory shrinks significantly... The query caches are almost exactly 50% smaller, and target as a whole is 27.3% smaller in Ruff and 31.1% smaller in uv.

@rustbot rustbot added A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 3, 2026
@rustbot

rustbot commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

r? @TaKO8Ki

rustbot has assigned @TaKO8Ki.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 75 candidates
  • Random selection from 20 candidates

@rustbot

This comment has been minimized.

@charliermarsh charliermarsh changed the title Collect superseded incremental compilation sessions Garbage-collect superseded incremental compilation sessions Sep 3, 2026
@charliermarsh
charliermarsh force-pushed the charlie/incremental-session-gc branch from d7c7cb1 to 62352f9 Compare September 3, 2026 13:14
@charliermarsh charliermarsh changed the title Garbage-collect superseded incremental compilation sessions Garbage-collect old incremental compilation sessions Sep 3, 2026
@charliermarsh
charliermarsh force-pushed the charlie/incremental-session-gc branch from 62352f9 to bc21abb Compare September 3, 2026 13:15
@lqd

lqd commented Sep 3, 2026

Copy link
Copy Markdown
Member

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 3, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Sep 3, 2026
… r=<try>

Garbage-collect old incremental compilation sessions
@rust-bors

rust-bors Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 0cc728b (0cc728b666accd70541869cd29761c27af2a1bda)
Base parent: d8df826 (d8df82673d5911b6112a85bf91d9adefb2c66a1a)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (0cc728b): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

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

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.1% [-0.1%, -0.1%] 1
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (secondary 7.2%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
7.2% [7.2%, 7.2%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

Results (secondary -2.6%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.7% [2.7%, 2.7%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-5.2% [-6.2%, -4.2%] 2
All ❌✅ (primary) - - 0

Binary size

Results (primary 0.0%, secondary 0.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.0% [0.0%, 0.1%] 15
Regressions ❌
(secondary)
0.1% [0.0%, 0.1%] 5
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.0% [0.0%, 0.1%] 15

Bootstrap: 477.112s -> 477.159s (0.01%)
Artifact size: 401.86 MiB -> 401.22 MiB (-0.16%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 3, 2026
@lqd

lqd commented Sep 3, 2026

Copy link
Copy Markdown
Member

It’s the previous behavior isn’t intended, so this fix would make sense. What do you think @bjorn3?

Comment thread compiler/rustc_incremental/src/persist/fs.rs Outdated
@bjorn3

This comment was marked as resolved.

@bjorn3

bjorn3 commented Sep 14, 2026

Copy link
Copy Markdown
Member

@bors r+

@rust-bors

rust-bors Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

📌 Commit b4361c9 has been approved by bjorn3

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 14, 2026
@bjorn3

bjorn3 commented Sep 14, 2026

Copy link
Copy Markdown
Member

r? bjorn3

@rustbot rustbot assigned bjorn3 and unassigned TaKO8Ki Sep 14, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 14, 2026
…session-gc, r=bjorn3

Garbage-collect old incremental compilation sessions

## Summary

rustc cleans up old incremental-cache snapshots twice during a compilation: once at startup (after loading the previous cache), and then again after finishing and finalizing the new cache.

In rust-lang#147821, we started skipping the current session during cleanup. But that means we're also skipping cleanup _after_ the session has finished, so we're keeping _both_ the previous and the completed snapshot on disk. (The snapshots don't accumulate indefinitely -- the "extra" snapshot gets removed when the next compilation starts, but that compilation then leaves another snapshot behind when it finishes.)

This PR modifies the logic to skip the current session while it is still active, but remove it once finalized.

Testing it locally for [Ruff](https://github.com/astral-sh/ruff) and [uv](https://github.com/astral-sh/uv), the target directory shrinks significantly... The query caches are almost exactly 50% smaller, and `target` as a whole is 27.3% smaller in Ruff and 31.1% smaller in uv.
rust-bors Bot pushed a commit that referenced this pull request Sep 14, 2026
…uwer

Rollup of 11 pull requests

Successful merges:

 - #162752 (`rust-analyzer` subtree update)
 - #161868 (libtest: never iterate over all tests in `--exact` mode)
 - #161903 (Fix initialization cycle in `target_config`)
 - #162240 (Garbage-collect old incremental compilation sessions)
 - #161675 (document that t-lang does not need involvement for unobservable intrisics)
 - #162630 (Simplify the `G` in `Diag<'a, G>`)
 - #162647 (Add regression test for previous overflow evaluating the requirement)
 - #162703 (regression test for valtree leaf const)
 - #162723 (Add regression test for unexpected type for constructor)
 - #162735 (Remove pointless `A: Allocator` bounds in boxed.rs)
 - #162736 (clean up trivial region constraint filtering)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 14, 2026
…session-gc, r=bjorn3

Garbage-collect old incremental compilation sessions

## Summary

rustc cleans up old incremental-cache snapshots twice during a compilation: once at startup (after loading the previous cache), and then again after finishing and finalizing the new cache.

In rust-lang#147821, we started skipping the current session during cleanup. But that means we're also skipping cleanup _after_ the session has finished, so we're keeping _both_ the previous and the completed snapshot on disk. (The snapshots don't accumulate indefinitely -- the "extra" snapshot gets removed when the next compilation starts, but that compilation then leaves another snapshot behind when it finishes.)

This PR modifies the logic to skip the current session while it is still active, but remove it once finalized.

Testing it locally for [Ruff](https://github.com/astral-sh/ruff) and [uv](https://github.com/astral-sh/uv), the target directory shrinks significantly... The query caches are almost exactly 50% smaller, and `target` as a whole is 27.3% smaller in Ruff and 31.1% smaller in uv.
rust-bors Bot pushed a commit that referenced this pull request Sep 14, 2026
…uwer

Rollup of 15 pull requests

Successful merges:

 - #162752 (`rust-analyzer` subtree update)
 - #161903 (Fix initialization cycle in `target_config`)
 - #162240 (Garbage-collect old incremental compilation sessions)
 - #162610 (fix tailcall indirect return)
 - #162634 (Implement semantic analysis for named `Fn` trait params)
 - #161675 (document that t-lang does not need involvement for unobservable intrisics)
 - #162160 (turn aligned-in-packed error into lint)
 - #162504 (Stabilize `unsafe_cell_access`)
 - #162516 (tidy: Sort multi-line types by treating `>` as a closing bracket)
 - #162630 (Simplify the `G` in `Diag<'a, G>`)
 - #162647 (Add regression test for previous overflow evaluating the requirement)
 - #162703 (regression test for valtree leaf const)
 - #162723 (Add regression test for unexpected type for constructor)
 - #162735 (Remove pointless `A: Allocator` bounds in boxed.rs)
 - #162736 (clean up trivial region constraint filtering)
rust-bors Bot pushed a commit that referenced this pull request Sep 14, 2026
…uwer

Rollup of 16 pull requests

Successful merges:

 - #162762 (Subtree sync for rustc_codegen_cranelift)
 - #162752 (`rust-analyzer` subtree update)
 - #161903 (Fix initialization cycle in `target_config`)
 - #162240 (Garbage-collect old incremental compilation sessions)
 - #162610 (fix tailcall indirect return)
 - #162634 (Implement semantic analysis for named `Fn` trait params)
 - #161675 (document that t-lang does not need involvement for unobservable intrisics)
 - #162160 (turn aligned-in-packed error into lint)
 - #162504 (Stabilize `unsafe_cell_access`)
 - #162516 (tidy: Sort multi-line types by treating `>` as a closing bracket)
 - #162630 (Simplify the `G` in `Diag<'a, G>`)
 - #162647 (Add regression test for previous overflow evaluating the requirement)
 - #162703 (regression test for valtree leaf const)
 - #162723 (Add regression test for unexpected type for constructor)
 - #162735 (Remove pointless `A: Allocator` bounds in boxed.rs)
 - #162736 (clean up trivial region constraint filtering)
@rust-bors
rust-bors Bot merged commit f654635 into rust-lang:main Sep 14, 2026
13 checks passed
@rustbot rustbot added this to the 1.100.0 milestone Sep 14, 2026
rust-bors Bot pushed a commit that referenced this pull request Sep 14, 2026
Rollup merge of #162240 - charliermarsh:charlie/incremental-session-gc, r=bjorn3

Garbage-collect old incremental compilation sessions

## Summary

rustc cleans up old incremental-cache snapshots twice during a compilation: once at startup (after loading the previous cache), and then again after finishing and finalizing the new cache.

In #147821, we started skipping the current session during cleanup. But that means we're also skipping cleanup _after_ the session has finished, so we're keeping _both_ the previous and the completed snapshot on disk. (The snapshots don't accumulate indefinitely -- the "extra" snapshot gets removed when the next compilation starts, but that compilation then leaves another snapshot behind when it finishes.)

This PR modifies the logic to skip the current session while it is still active, but remove it once finalized.

Testing it locally for [Ruff](https://github.com/astral-sh/ruff) and [uv](https://github.com/astral-sh/uv), the target directory shrinks significantly... The query caches are almost exactly 50% smaller, and `target` as a whole is 27.3% smaller in Ruff and 31.1% smaller in uv.
github-actions Bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Sep 17, 2026
…uwer

Rollup of 16 pull requests

Successful merges:

 - rust-lang/rust#162762 (Subtree sync for rustc_codegen_cranelift)
 - rust-lang/rust#162752 (`rust-analyzer` subtree update)
 - rust-lang/rust#161903 (Fix initialization cycle in `target_config`)
 - rust-lang/rust#162240 (Garbage-collect old incremental compilation sessions)
 - rust-lang/rust#162610 (fix tailcall indirect return)
 - rust-lang/rust#162634 (Implement semantic analysis for named `Fn` trait params)
 - rust-lang/rust#161675 (document that t-lang does not need involvement for unobservable intrisics)
 - rust-lang/rust#162160 (turn aligned-in-packed error into lint)
 - rust-lang/rust#162504 (Stabilize `unsafe_cell_access`)
 - rust-lang/rust#162516 (tidy: Sort multi-line types by treating `>` as a closing bracket)
 - rust-lang/rust#162630 (Simplify the `G` in `Diag<'a, G>`)
 - rust-lang/rust#162647 (Add regression test for previous overflow evaluating the requirement)
 - rust-lang/rust#162703 (regression test for valtree leaf const)
 - rust-lang/rust#162723 (Add regression test for unexpected type for constructor)
 - rust-lang/rust#162735 (Remove pointless `A: Allocator` bounds in boxed.rs)
 - rust-lang/rust#162736 (clean up trivial region constraint filtering)
bjorn3 pushed a commit to rust-lang/rustc_codegen_cranelift that referenced this pull request Sep 18, 2026
…uwer

Rollup of 16 pull requests

Successful merges:

 - rust-lang/rust#162762 (Subtree sync for rustc_codegen_cranelift)
 - rust-lang/rust#162752 (`rust-analyzer` subtree update)
 - rust-lang/rust#161903 (Fix initialization cycle in `target_config`)
 - rust-lang/rust#162240 (Garbage-collect old incremental compilation sessions)
 - rust-lang/rust#162610 (fix tailcall indirect return)
 - rust-lang/rust#162634 (Implement semantic analysis for named `Fn` trait params)
 - rust-lang/rust#161675 (document that t-lang does not need involvement for unobservable intrisics)
 - rust-lang/rust#162160 (turn aligned-in-packed error into lint)
 - rust-lang/rust#162504 (Stabilize `unsafe_cell_access`)
 - rust-lang/rust#162516 (tidy: Sort multi-line types by treating `>` as a closing bracket)
 - rust-lang/rust#162630 (Simplify the `G` in `Diag<'a, G>`)
 - rust-lang/rust#162647 (Add regression test for previous overflow evaluating the requirement)
 - rust-lang/rust#162703 (regression test for valtree leaf const)
 - rust-lang/rust#162723 (Add regression test for unexpected type for constructor)
 - rust-lang/rust#162735 (Remove pointless `A: Allocator` bounds in boxed.rs)
 - rust-lang/rust#162736 (clean up trivial region constraint filtering)
@bjorn3 bjorn3 added the A-incr-comp Area: Incremental compilation label Sep 18, 2026
pull Bot pushed a commit to xtqqczze/rust-lang-rust-analyzer that referenced this pull request Sep 21, 2026
…uwer

Rollup of 16 pull requests

Successful merges:

 - rust-lang/rust#162762 (Subtree sync for rustc_codegen_cranelift)
 - rust-lang/rust#162752 (`rust-analyzer` subtree update)
 - rust-lang/rust#161903 (Fix initialization cycle in `target_config`)
 - rust-lang/rust#162240 (Garbage-collect old incremental compilation sessions)
 - rust-lang/rust#162610 (fix tailcall indirect return)
 - rust-lang/rust#162634 (Implement semantic analysis for named `Fn` trait params)
 - rust-lang/rust#161675 (document that t-lang does not need involvement for unobservable intrisics)
 - rust-lang/rust#162160 (turn aligned-in-packed error into lint)
 - rust-lang/rust#162504 (Stabilize `unsafe_cell_access`)
 - rust-lang/rust#162516 (tidy: Sort multi-line types by treating `>` as a closing bracket)
 - rust-lang/rust#162630 (Simplify the `G` in `Diag<'a, G>`)
 - rust-lang/rust#162647 (Add regression test for previous overflow evaluating the requirement)
 - rust-lang/rust#162703 (regression test for valtree leaf const)
 - rust-lang/rust#162723 (Add regression test for unexpected type for constructor)
 - rust-lang/rust#162735 (Remove pointless `A: Allocator` bounds in boxed.rs)
 - rust-lang/rust#162736 (clean up trivial region constraint filtering)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-incr-comp Area: Incremental compilation A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants