Skip to content

Resolver: Parallelize the import resolution loop - #158845

Open
LorrensP-2158466 wants to merge 1 commit into
rust-lang:mainfrom
LorrensP-2158466:parallel-import-resolution
Open

LorrensP-2158466 wants to merge 1 commit into
rust-lang:mainfrom
LorrensP-2158466:parallel-import-resolution

Conversation

@LorrensP-2158466

@LorrensP-2158466 LorrensP-2158466 commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

View all comments

Follow up of #159440. This pr implements the parallel part of par_for_each_slice. And implements DynSend and DynSync for RefOrMut and CmCell to make the call to par_for_each_slice compile.

This is the bare minimum to make the parallel loop work and is not at all optimized, this will follow :).

r? @petrochenkov

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 6, 2026
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jul 6, 2026
@LorrensP-2158466

Copy link
Copy Markdown
Contributor Author

Lets see what CI says.

I have tried to add comments to changes to show my thought process behind them, but i'll make another pass here as well to be sure.

Comment thread compiler/rustc_data_structures/src/sync/parallel.rs Outdated
Comment thread compiler/rustc_resolve/src/build_reduced_graph.rs Outdated
Comment thread compiler/rustc_resolve/src/imports.rs Outdated
Comment thread compiler/rustc_resolve/src/imports.rs
Comment thread compiler/rustc_resolve/src/imports.rs Outdated
Comment thread compiler/rustc_resolve/src/imports.rs Outdated
@rust-log-analyzer

This comment has been minimized.

Comment thread compiler/rustc_resolve/src/lib.rs Outdated
Comment thread compiler/rustc_resolve/src/lib.rs Outdated
Comment thread compiler/rustc_resolve/src/lib.rs Outdated
@rust-log-analyzer

This comment has been minimized.

@LorrensP-2158466
LorrensP-2158466 force-pushed the parallel-import-resolution branch from 17bd1cb to 9aa1069 Compare July 6, 2026 10:48
@rust-log-analyzer

This comment has been minimized.

@LorrensP-2158466
LorrensP-2158466 force-pushed the parallel-import-resolution branch from 9aa1069 to a45ba86 Compare July 6, 2026 11:31
@petrochenkov petrochenkov added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 6, 2026
@petrochenkov

Copy link
Copy Markdown
Contributor

@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 Jul 6, 2026
@rust-bors

This comment has been minimized.

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

Resolver: Parallelize the import resolution loop
Comment thread compiler/rustc_data_structures/src/sync.rs Outdated
Comment thread compiler/rustc_interface/src/passes.rs Outdated
Comment thread compiler/rustc_resolve/src/lib.rs Outdated
Comment thread compiler/rustc_resolve/src/lib.rs Outdated
Comment thread compiler/rustc_resolve/src/lib.rs Outdated
Comment thread compiler/rustc_resolve/src/lib.rs Outdated
Comment thread compiler/rustc_resolve/src/lib.rs Outdated
Comment thread compiler/rustc_resolve/src/build_reduced_graph.rs Outdated
Comment thread compiler/rustc_resolve/src/build_reduced_graph.rs Outdated
Comment thread compiler/rustc_resolve/src/build_reduced_graph.rs Outdated
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 6, 2026
@rust-bors

rust-bors Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 3df1fed (3df1fed3aaf1081aa59cfe2228eed289a2ef744e)
Base parent: 3c00c96 (3c00c96d3af4d5b5e101e56cc161a608b21366ee)

@rust-timer

This comment has been minimized.

@petrochenkov

Copy link
Copy Markdown
Contributor

decided to create a CmToken instead of using &mut Resolver in these things, seems cleaner to me at least

Again, we'll need to benchmark whether eliding this boolean assert even matters, considering that it's not even atomic.

@LorrensP-2158466

Copy link
Copy Markdown
Contributor Author

I'll split the CmRefCell changes as well (first without token). Okey with you?

@petrochenkov

Copy link
Copy Markdown
Contributor

I'll split the CmRefCell changes as well (first without token). Okey with you?

Yes, after the ResolutionTable lands

@rust-bors

This comment has been minimized.

@rustbot

This comment has been minimized.

@LorrensP-2158466

Copy link
Copy Markdown
Contributor Author

Rebased to fix conflicts and cleanup the PR, it now contains:

@rustbot ready.

@petrochenkov

petrochenkov commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

I don't think we'll merge this part, given the unconvincing perf results from the linked PR and the amount of complexity/unsafety.
Could you remove it from this PR? We could benchmark it later separately (but probably still not merge).

Comment thread compiler/rustc_resolve/src/lib.rs Outdated
Comment thread compiler/rustc_resolve/src/lib.rs Outdated
Comment thread compiler/rustc_resolve/src/ident.rs Outdated
Comment thread compiler/rustc_resolve/src/lib.rs Outdated
@rustbot

This comment has been minimized.

@LorrensP-2158466

Copy link
Copy Markdown
Contributor Author

Force-pushed to keep up to date (and remove RwLock change) and address both comments + the removal of Cache(Ref)Cell.

i'll wait on #158845 (comment), so i'll mark this @rustbot ready.

Comment thread compiler/rustc_resolve/src/lib.rs
Comment thread compiler/rustc_resolve/src/ident.rs Outdated
@petrochenkov

Copy link
Copy Markdown
Contributor

Could you move the Cache(Ref)Cell parts to a separate PR so they could be benchmarked separately?
@rustbot author

@rust-bors

This comment has been minimized.

… parallel loop for import resolution.

+ impl `DynSend`/`DynSync` for all relevant data structures.
+ safety comments.
@rustbot

rustbot commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@LorrensP-2158466

Copy link
Copy Markdown
Contributor Author

rebased to fix conflicts and squash to one commit. @rustbot ready

@petrochenkov

Copy link
Copy Markdown
Contributor

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rust-bors

rust-bors Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: dccb2bf (dccb2bfebc75e0c44545ab9e2cd326c835d5a30b)
Base parent: e67cfe8 (e67cfe858e65fc23ae3c7ea118fb7178d6bc4b05)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (dccb2bf): comparison URL.

Overall result: no relevant changes - 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

This perf run didn't have relevant results for this metric.

Max RSS (memory usage)

Results (primary 1.9%, secondary 2.9%)

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

mean range count
Regressions ❌
(primary)
3.1% [2.8%, 3.7%] 4
Regressions ❌
(secondary)
2.9% [2.9%, 2.9%] 1
Improvements ✅
(primary)
-2.5% [-2.5%, -2.5%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.9% [-2.5%, 3.7%] 5

Cycles

Results (primary -3.7%, secondary -4.1%)

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.6% [2.6%, 2.6%] 1
Improvements ✅
(primary)
-3.7% [-5.3%, -2.0%] 8
Improvements ✅
(secondary)
-4.8% [-9.5%, -3.0%] 9
All ❌✅ (primary) -3.7% [-5.3%, -2.0%] 8

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 488.069s -> 491.874s (0.78%)
Artifact size: 406.51 MiB -> 406.53 MiB (0.00%)

@petrochenkov

Copy link
Copy Markdown
Contributor

Ok, the implementation is good, now we need any benchmark showing that parallelizing import resolution is actually useful, and we can merge this.
@rustbot author

@LorrensP-2158466

Copy link
Copy Markdown
Contributor Author

@petrochenkov Sorry for asking this... 😅

but by "any benchmark" do you mean any parallel benchmark of rustc-perf? or compiling some crates locally and showing that compile times improve with paralel import resolution and -threads>1?

@petrochenkov

Copy link
Copy Markdown
Contributor

Not necessarily from rustc-perf, just any benchmark that shows green numbers from this change.
Perhaps even a synthetic one with lots of imports, although that would be a bit disappointing (from the standard rustc-perf benchmarks unused-warnings is one such benchmark).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

5 participants