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
};

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.

TokenIds are auto-increment identifiers for Definitions (which would be
better named Symbol according to its docstring). This auto-increment
property creates shared state that makes a TokenStore diffucult to
share accross threads and merging multiple StaticIndex instances non-
trivial.

Instead we can just use Definition itself which is Hash and Copy.

This changes the order tokens are iterated on in lsif.rs:334.
…ysis

Each thread will have its own Analysis clone, and return a partial
StaticIndex to the main thread. Thus StaticIndex must survive Analysis.
Thanks to the 4 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
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.
When multi-threading StaticIndex::compute, we want the list of files to
be computed only once and the files to be split between threads.
When multi-threading StaticIndex::compute, each thread will get its own
Analysis clone.
@rustbot

rustbot commented Jun 6, 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.

@nicolas-guichard nicolas-guichard requested a review from Veykril June 16, 2026 13:19
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