Skip to content

Commit 32f3330

Browse files
committed
add a bit more on parallel compilation
1 parent 158caa9 commit 32f3330

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
- [Profiling Queries](./queries/profiling.md)
4545
- [Salsa](./salsa.md)
4646
- [Memory Management in Rustc](./memory.md)
47+
- [Parallel Compilation](./parallel-rustc.md)
4748

4849
- [Part 3: Source Code Representations](./part-3-intro.md)
4950
- [The Rustc Driver and Interface](./rustc-driver.md)

src/parallel-rustc.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Parallel Compilation
2+
3+
Most of the compiler is not parallel. This represents an opportunity for
4+
improving compiler performance. Much effort has been put into parallelizing
5+
`rustc`, but it is still pretty early days for this work. There is a lot of
6+
design and correctness work that needs to be done.
7+
8+
One can try out the current parallel compiler work by enabling it in the
9+
`config.toml`.
10+
11+
There are a few basic ideas in this effort:
12+
13+
- There are a lot of loops in the compiler that just iterate over all items in
14+
a crate. These can possibly be parallelized.
15+
- We can use (a custom fork of) [`rayon`] to run tasks in parallel. The custom
16+
fork allows the execution of DAGs of tasks, not just trees.
17+
- There are currently a lot of global data structures that need to be made
18+
thread-safe. A key strategy here has been converting interior-mutable
19+
data-structures (e.g. `Cell`) into their thread-safe siblings (e.g. `Mutex`).
20+
21+
[`rayon`]: https://crates.io/rayon
22+
23+
As of this writing, much of this effort is on hold due to lack of manpower. We
24+
have a working prototype with promising performance gains in many cases.
25+
However, there are two blockers:
26+
27+
- It's not clear what invariants need to be upheld that might not hold in the
28+
face of concurrency. An auditing effort was underway, but seems to have
29+
stalled at some point.
30+
31+
- There is a lot of lock contention, which actually degrades performance as the
32+
number of threads increases beyond 4.
33+
34+
Here are some resources that can used to learn more (note that some of them are
35+
a bit out of date):
36+
37+
- [This IRLO thread by Zoxc, when of the pioneers of the effort][irlo0]
38+
- [This list of interior mutability in the compiler by nikomatsakis][imlist]
39+
- [This IRLO thread by alexchricton about performance][irlo1]
40+
- [This tracking issue][tracking]
41+
42+
[irlo0]: https://internals.rust-lang.org/t/parallelizing-rustc-using-rayon/6606
43+
[imlist]: https://github.com/nikomatsakis/rustc-parallelization/blob/master/interior-mutability-list.md
44+
[irlo1]: https://internals.rust-lang.org/t/help-test-parallel-rustc/11503
45+
[tracking]: https://github.com/rust-lang/rust/issues/48685

0 commit comments

Comments
 (0)