# Parallel Rustc Work List
## make nightly compilers able to parallelize
The goal is to reduce the efficiency regression with `-Zthread=1` to within 1% compared to the non-parallel compiler
https://github.com/rust-lang/rust/pull/101566
- [x] Work1. Continuously analyze the specific reasons for the performance regression caused by the parallel compiler when `-Zthreads=1`, and initially formulate a solution.
- [x] Work2. Find a good way to reconstruct the `Lock` data structure so that the cost of parallelization is acceptable while remaining thread-safety.
- [ ] Work3. Refactor other shared data structures to eliminate all conditional compilation code of `parallel_compiler`
There is no strong dependency between the above tasks, so they can be addressed in parallel.
| reason | initial solution |
| ------------------------------------------------------------ | ------------------------------------------------------------ |
| `Mutex` is too heavy than `RefCell` in `Lock` struct | 1. Use `RefCell` when threads=1 and `Mutex` when threads > 1 in `Lock` struct. We can use `DynSend` and `DynSync` auto trait to ensure thread safety here |
make `GatedSpans` when parsing | Move `gated_spans` from `ParseSess` to `Parser` to avoid `Lock::lock()` |
| Access `Lock` in `HygieneEncodeContext` when encoding metadata | Change `hygiene_ctxt` in `EncodeContext` from `&'a HygieneEncodeContext` to `HygieneEncodeContext` to delete `Lock` |
| use unnecessary Lock in infcx's caches | use RefCell in infcx's `selection_cache` and `evaluation_cache` |
use `Lock` in SourceFile | use `RwLock` in `SourceFile.external_src` and `SourceFile.lines` |
| ... | |
## Adaptation of rustc-perf to parallel compilers
Improve rustc-perf's support for parallel compilers. The lead developers for this part of the work are @nnethercote and @Jakub Beránek.
- [ ] // discussion needed
## Test for parallel compilers
- [ ] The current ui tests is only tested for `-Zthreads=1`, we should increase the test under multiple threads.
- [ ] Deal with the output order of diagnostic information under multi-threading
- [ ] Benchmarks for parallel compilers. Such as the number of calls to `Lock` and the blocking time of each thread. A related issue form @bjorn3 [here](https://github.com/rust-lang/rust/issues/92596).
## Deepen compiler parallelism
Analyze the feasibility of parallelizing other parts of compilation process
- [ ] Lex parsing
- [ ] Expansion (with import resolving)
- [ ] name resolving
- [ ] linking
...