Skip to content
This repository was archived by the owner on Oct 25, 2021. It is now read-only.

Commit 1a6c48e

Browse files
authored
Add "Rust Trait System Revamp" grant proposal. (#261)
* Add "Rust Trait System Revamp" grant proposal. * Clarify milestone details (e.g. the reports). * Clarify that work will happen upstream (rust-lang/rust).
1 parent 7a88eb2 commit 1a6c48e

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Rust Trait System Revamp
2+
3+
## Project Description
4+
We want to improve the Rust trait system, to offer more profiling insight and remove redundant work, in order to ultimately increase its performance.
5+
6+
This will help speed up compilation of Substrate / Polkadot crates, as they rely a lot on Rust traits, including type-level metaprogramming with associated types.
7+
8+
Our team has previously investigated Polkadot compile times, which resulted in [`rust-lang/rust#66821`](https://github.com/rust-lang/rust/pull/66821) being merged upstream, giving the `polkadot-runtime` crate an almost 3x speed-up for release mode compilation.
9+
10+
## Team members
11+
* Eduard-Mihai Burtescu
12+
* Ana-Maria Mihalache
13+
* Ioan-Valentin Lazureanu
14+
15+
## Team Website
16+
* https://lyken.rs
17+
18+
## Legal Structure
19+
"Lyken Software Solutions SRL", a LLC registered in Romania.
20+
Full details shared via the associated Google Form.
21+
22+
## Team's experience
23+
Eduard-Mihai Burtescu has been working the Rust Compiler for the past 6 years, and [is a top contributor](https://github.com/rust-lang/rust/graphs/contributors?type=d#contributors) to [`rust-lang/rust`](https://github.com/rust-lang/rust).
24+
25+
In 2017 he founded Lyken Software Solutions, which has been offering Rust-adjacent software consultancy services, with a specialization in the Rust Compiler. We have since worked with Mozilla and others to improve various aspects of Rust, including speeding up Polkadot compilation for Web3 Foundation, in late 2019.
26+
27+
## Team Code Repos
28+
* [@LykenSol](https://github.com/LykenSol)
29+
30+
## Team LinkedIn Profiles
31+
* https://www.linkedin.com/in/eduard-mihai-burtescu-74a7bb69/
32+
* https://www.linkedin.com/in/ana-maria-mihalache-5071081a4/
33+
* https://www.linkedin.com/in/valentin-l%C4%83zureanu-a6563712b/
34+
35+
## Development Roadmap
36+
37+
### Milestone 1 — Low-overhead trait system profiling — 1 month — $10,000
38+
The Rust Compiler "Self-Profiling" feature is available through the nightly-only `-Z self-profile` flag and [`measureme`](https://github.com/rust-lang/measureme) tools, which include [documentation on profiling the Rust Compiler](https://github.com/rust-lang/measureme/blob/master/summarize/Readme.md#profiling-the-nightly-compiler).
39+
40+
We will integrate the Rust Compiler's trait system operations with the Self-Profiling feature, using proven techniques to record detailed information (i.e. specific traits and types being operated on) without introducing timing inaccuracies.
41+
42+
We will submit these changes as a Pull Request to the official Rust Compiler repository ([`rust-lang/rust`](https://github.com/rust-lang/rust) on GitHub).
43+
44+
We will demonstrate this new profiling data in a report, showing, for representative Polkadot and Substrate crates:
45+
* how much of the compilation is spent in the trait system (which previously would've showed up on profiles as part of type-checking and borrow-checking)
46+
* the most common types or traits, accounting for a significant fraction of the time spent in the trait system
47+
* any examples we can find of redundant or outright wasteful trait system operations which still take non-trivial amounts of time
48+
49+
Our report will also include all of the steps we performed to collect and analyze the profiling data.
50+
51+
This kind of fine-grained accurate profiling information will be essential to understanding where time is being wasted, and where we should focus all further efforts.
52+
53+
### Milestone 2 — Improved trait system caching — 1 month — $10,000
54+
We've identified defficiencies in the caching performed by the Rust Compiler's trait system, which we'll be able to better analyze once **Milestone 1** is completed.
55+
56+
We will then address them, to increase the effectiveness of caching in the Rust Compiler's trait system. Some of the potential changes we're considering to that end are:
57+
* precomputing "type flags" for type/trait system lists, not just types
58+
* introducing fast paths for common simple cases
59+
* distinguishing bounds that mention generic parameters from those that do not
60+
* removing non-global (i.e. per-inference-context) caches
61+
* replacing obsolete "freshening" with the newer "canonicalization"
62+
* incorporating postprocessing (e.g. "candidate confirmation") into the cached data
63+
64+
The above list is not exhaustive, as other opportunities may present themselves.
65+
66+
We will submit these changes as Pull Requests to the official Rust Compiler repository ([`rust-lang/rust`](https://github.com/rust-lang/rust) on GitHub).
67+
68+
We will demonstrate the reduction in compile times from these changes in a report, showing:
69+
* overall changes in compile times across Polkadot and Substrate
70+
* differences in the fine-grained profiling data from **Milestone 1**, in both the number of operations performed and their average duration
71+
72+
### Milestone 3 — Global caching for associated type projection — 1 month — $10,000
73+
The Rust Compiler does not currently cache resolving associated types (i.e. "projecting" them) for the whole compilation at all, but rather only within individual (e.g. function) definitions.
74+
75+
We will extend the existing associated type projection caching in the Rust Compiler to be shared across the entire compilation, similarly to the rest of the trait system, and including any applicable techniques from **Milestone 2**.
76+
77+
We will submit these changes as Pull Requests to the official Rust Compiler repository ([`rust-lang/rust`](https://github.com/rust-lang/rust) on GitHub).
78+
79+
We will demonstrate the reduction in compile times from these changes in a report, showing:
80+
* overall changes in compile times across Polkadot and Substrate
81+
* differences in the fine-grained profiling data from **Milestone 2**, in both the number of operations performed and their average duration
82+
83+
## Future Plans
84+
Long-term, we may contribute to the Chalk project, especially its integration into the Rust Compiler and the performance of the resulting system.
85+
But in the meanwhile we will continue to look for potential improvements in the current Rust Compiler codebase.
86+
87+
## Additional Information
88+
We have already done some quick and approximate data gathering, which suggests that up to a quarter of `polkadot-runtime-common`'s checking time (i.e. comparable with debug mode build times) is spent doing redundant work in the trait system.
89+
However, acquiring more accurate statistics would only be possible after **Milestone 1** is completed.

0 commit comments

Comments
 (0)