Run StaticIndex::compute over multiple threads - #22530
Conversation
| }; | ||
|
|
||
| for (def, token) in tokens { | ||
| lsif.add_token(def, token); |
There was a problem hiding this comment.
I'm not too happy about this: ideally lsif_contains_generated_constant would be order-independent but is it worth the time?
This comment has been minimized.
This comment has been minimized.
23b27c3 to
a7252fb
Compare
This comment has been minimized.
This comment has been minimized.
a7252fb to
4d8ada8
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
4d8ada8 to
6250837
Compare
This comment has been minimized.
This comment has been minimized.
6250837 to
0ab7eb0
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
0ab7eb0 to
dfcc680
Compare
This comment has been minimized.
This comment has been minimized.
a3d51d7 to
0bd261e
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
0bd261e to
aba406e
Compare
This comment has been minimized.
This comment has been minimized.
aba406e to
55b7509
Compare
|
I had to rework this because of the new lifetime in This is actually more efficient in CPU time than my first iteration which built a
|
55b7509 to
b2eac38
Compare
This comment has been minimized.
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.
b2eac38 to
fe3fec0
Compare
|
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. |
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