Skip to content

Run StaticIndex::compute over multiple threads - #22530

Open
nicolas-guichard wants to merge 5 commits into
rust-lang:masterfrom
nicolas-guichard:push-xqywvtlynoxs
Open

Run StaticIndex::compute over multiple threads#22530
nicolas-guichard wants to merge 5 commits into
rust-lang:masterfrom
nicolas-guichard:push-xqywvtlynoxs

Conversation

@nicolas-guichard

@nicolas-guichard nicolas-guichard commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Each thread takes care of the files whose index in the precomputed list is congruent to the thread index modulo the thread count and generates a partial StaticIndex. All those StaticIndex instances are then simply concatenated together.

On my laptop with 16 threads this brings the time required to generate an SCIP index of Firefox from 80 seconds with 160% CPU usage down to 30 seconds, with 600% CPU usage.

Fixes #18140

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 5, 2026
Comment thread crates/rust-analyzer/src/cli/lsif.rs Outdated
};

for (def, token) in tokens {
lsif.add_token(def, token);

@nicolas-guichard nicolas-guichard Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too happy about this: ideally lsif_contains_generated_constant would be order-independent but is it worth the time?

View changes since the review

Comment thread crates/ide/src/folding_ranges.rs
Comment thread crates/ide/src/static_index.rs Outdated
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@nicolas-guichard
nicolas-guichard force-pushed the push-xqywvtlynoxs branch 2 times, most recently from a3d51d7 to 0bd261e Compare July 17, 2026 12:36
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@nicolas-guichard

Copy link
Copy Markdown
Contributor Author

I had to rework this because of the new lifetime in Definition<'db> added in #22548. This reverts to using two maps Definition<'db>TokenId and TokenIdTokenStaticData so that the final StaticIndex doesn't depend on the Analysis lifetime.

This is actually more efficient in CPU time than my first iteration which built a DefinitionTokenStaticData map per thread then merged them (thus doing redundant work).

time says for rust-analyzer scip firefox:

  • 1649637 (old master): 141,50s user 5,38s system 131% cpu 1:51,64 total
  • 0bd261e (old pr rev): 283,77s user 6,31s system 748% cpu 38,769 total
  • 1174734 (new master): 142,98s user 5,12s system 130% cpu 1:53,39 total
  • 55b7509 (new pr rev): 190,18s user 6,03s system 431% cpu 45,470 total

@rustbot

This comment has been minimized.

When multi-threading StaticIndex::compute, each thread will get its own
Analysis clone.
When multi-threading StaticIndex::compute, we want the list of files to
be computed only once and the files to index to be split between
threads.
The analysis, db and def_map members of StaticIndex were only used for
building the index and are of no use once the index is built.

Instead of have an &mut self method which mutates those fields, we can
extract the FileId→StaticIndexedFile indexing into a free function and
keep the token_store and def_map as locals in StaticIndex::compute.

This will make multi-threading StaticIndex::compute easier.
Thanks to the previous commits, everything is in place to start
multiple threads in StaticIndex::compute.

Each thread takes care of the files whose index in the precomputed list
is congruent to the thread index modulo the thread count and generates
its StaticIndexedFile.

The Definition→TokenId and TokenId→TokenStaticData maps are shared
across all threads and are now DashMaps.

TokenStore now uses an AtomicUsize to generate new TokenIds.
@rustbot

rustbot commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master 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.

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

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SCIP indexing is single threaded

3 participants