|
| 1 | +# Promoting Parallel Front End |
| 2 | + |
| 3 | +| Metadata | | |
| 4 | +| --- | --- | |
| 5 | +| Owner(s) | @SparrowLii | |
| 6 | +| Teams | [compiler] | |
| 7 | +| Status | Accepted | |
| 8 | +| Tracking issue | [rust-lang/rust-project-goals#121] | |
| 9 | + |
| 10 | + |
| 11 | +## Summary |
| 12 | + |
| 13 | +Continue to parallelize front-end stabilization and performance improvements, continuing from the [2024h2 goal](https://rust-lang.github.io/rust-project-goals/2024h2/parallel-front-end.html). |
| 14 | + |
| 15 | +## Motivation |
| 16 | + |
| 17 | +There are still some occasional deadlock issues, and in environments with high thread counts (>16) performance may be reduced due to data races. |
| 18 | + |
| 19 | +### The status quo |
| 20 | + |
| 21 | +Many current [issues] reflect ICE or deadlock problems that occur during the use of parallel front end. We need to resolve these issues to enhance its robustness. We also need theoretical algorithms to detect potential deadlocks in query systems. |
| 22 | + |
| 23 | +The current parallel front end still has room for further improvement in compilation performance, such as parallelization of HIR lowering and macro expansion, and reduction of data contention under more threads (>= 16). |
| 24 | + |
| 25 | +We can use parallel front end in bootstrap to alleviate the problem of slow build of the whole project. |
| 26 | + |
| 27 | +Cargo does not provide an option to enable the use of parallel front end, so it can only be enabled by passing rustc options manually. |
| 28 | + |
| 29 | +### The next 6 months |
| 30 | + |
| 31 | +- Solve reproducible deadlock issues via [tests](https://github.com/rust-lang/rust/pull/132051). |
| 32 | +- Enable parallel frontends in bootstrap. |
| 33 | +- Continue to improve parallel compilation performance, with the average speed increase from 20% to 25% under 8 cores and 8 threads. |
| 34 | +- Communicate with Cargo team on the solution and plan to support parallel front end. |
| 35 | + |
| 36 | +### The "shiny future" we are working towards |
| 37 | + |
| 38 | +We need a detection algorithm to theoretically prove that the current query system and query execution process do not bring potential deadlock problems. |
| 39 | + |
| 40 | +The existing rayon library implementation is difficult to fundamentally eliminate the deadlock problem, so we may need a better scheduling design to eliminate deadlock without affecting performance. |
| 41 | + |
| 42 | +The current compilation process with `GlobalContext` as the core of data storage is not very friendly to parallel front end. Maybe try to reduce the granularity (such as modules) to reduce data competition under more threads and improve performance. |
| 43 | + |
| 44 | +## Design axioms |
| 45 | + |
| 46 | +The parallel front end should be: |
| 47 | +- safe: Ensure the safe and correct execution of the compilation process |
| 48 | +- consistent: The compilation result should be consistent with that in single thread |
| 49 | +- maintainable: The implementation should be easy to maintain and extend, and not cause confusion to developers who are not familiar with it. |
| 50 | + |
| 51 | +[da]: ../about/design_axioms.md |
| 52 | + |
| 53 | +## Ownership and team asks |
| 54 | + |
| 55 | +**Owner:** @SparrowLii and Parallel Rustc WG own this goal |
| 56 | + |
| 57 | +| Subgoal | Owner(s) or team(s) | Notes | |
| 58 | +| ---------------------------- | -------------------- | ----- | |
| 59 | +| Implementation | @SparrowLii | | |
| 60 | +| Author tests | @SparrowLii | | |
| 61 | +| Discussion and moral support | ![Team][] [compiler] | | |
| 62 | + |
| 63 | +## Frequently asked questions |
| 64 | + |
| 65 | + |
| 66 | +[ICE]: https://github.com/rust-lang/rust/issues?q=is%3Aopen+label%3AWG-compiler-parallel+ice |
| 67 | +[deadlock]: https://github.com/rust-lang/rust/issues?q=is%3Aopen+label%3AWG-compiler-parallel+deadlock |
| 68 | +[test]: https://github.com/rust-lang/rust/issues/118698 |
| 69 | +[issues]: https://github.com/rust-lang/rust/labels/WG-compiler-parallel |
0 commit comments