From 4dd9682c25b1e7bf31b82483a38263e48e177b0f Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Fri, 6 Mar 2020 18:26:22 +0200 Subject: [PATCH 1/3] Add "Rust Trait System Revamp" grant proposal. --- .../speculative/rust_trait_system_revamp.md | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 grants/speculative/rust_trait_system_revamp.md diff --git a/grants/speculative/rust_trait_system_revamp.md b/grants/speculative/rust_trait_system_revamp.md new file mode 100644 index 000000000..8bb7f1e62 --- /dev/null +++ b/grants/speculative/rust_trait_system_revamp.md @@ -0,0 +1,66 @@ +# Rust Trait System Revamp + +## Project Description +We want to improve the Rust trait system, to offer more profiling insight and remove redundant work, in order to ultimately increase its performance. + +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. + +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. + +## Team members +* Eduard-Mihai Burtescu +* Ana-Maria Mihalache +* Ioan-Valentin Lazureanu + +## Team Website +* https://lyken.rs + +## Legal Structure +"Lyken Software Solutions SRL", a LLC registered in Romania. +Full details shared via the associated Google Form. + +## Team's experience +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). + +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. + +## Team Code Repos +* [@LykenSol](https://github.com/LykenSol) + +## Team LinkedIn Profiles +* https://www.linkedin.com/in/eduard-mihai-burtescu-74a7bb69/ +* https://www.linkedin.com/in/ana-maria-mihalache-5071081a4/ +* https://www.linkedin.com/in/valentin-l%C4%83zureanu-a6563712b/ + +## Development Roadmap + +### Milestone 1 — Low-overhead trait system profiling — 1 month — $10,000 +We will implement `-Z self-profile`/[`measureme`](https://github.com/rust-lang/measureme) support for the Rust compiler's trait system operations, using proven techniques to record detailed information without introducing timing inaccuracies. + +This kind of fine-grained accurate profiling information will be essential to understanding where time is being spent on redundant work, and where we should focus all further efforts. + +### Milestone 2 — Improved trait system caching — 1 month — $10,000 +We will increase the effectiveness of caches in the Rust compiler's trait system in a variety of ways, which may include: +* precomputing "type flags" for type/trait system lists, not just types +* introducing fast paths for common simple cases +* distinguishing bounds that mention generic parameters from those that do not +* removing non-global (i.e. per-inference-context) caches +* replacing obsolete "freshening" with the newer "canonicalization" +* caching more of the "trait (impl) selection" process + +The above list is not exhaustive, as other opportunities may present themselves. + +We will provide measurements across Polkadot and Substrate demonstrating the reduction in compile times from these changes. + +### Milestone 3 — Global caching for associated type projection — 1 month — $10,000 +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 advances from **Milestone 2**. + +We will provide measurements across Polkadot and Substrate demonstrating the reduction in compile times from these changes. + +## Future Plans +Long-term, we may contribute to the Chalk project, especially its integration into the Rust compiler and the performance of the resulting system. +But in the meanwhile we will continue to look for potential improvements in the current Rust compiler codebase. + +## Additional Information +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. +However, acquiring more accurate statistics would only be possible after **Milestone 1** is completed. From 2741ca458f6f19fd07506a18389c399b016d7548 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Fri, 13 Mar 2020 16:56:59 +0200 Subject: [PATCH 2/3] Clarify milestone details (e.g. the reports). --- .../speculative/rust_trait_system_revamp.md | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/grants/speculative/rust_trait_system_revamp.md b/grants/speculative/rust_trait_system_revamp.md index 8bb7f1e62..6124ae5b4 100644 --- a/grants/speculative/rust_trait_system_revamp.md +++ b/grants/speculative/rust_trait_system_revamp.md @@ -35,31 +35,48 @@ In 2017 he founded Lyken Software Solutions, which has been offering Rust-adjace ## Development Roadmap ### Milestone 1 — Low-overhead trait system profiling — 1 month — $10,000 -We will implement `-Z self-profile`/[`measureme`](https://github.com/rust-lang/measureme) support for the Rust compiler's trait system operations, using proven techniques to record detailed information without introducing timing inaccuracies. +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). -This kind of fine-grained accurate profiling information will be essential to understanding where time is being spent on redundant work, and where we should focus all further efforts. +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. + +We will demonstrate this new profiling data in a report, showing, for representative Polkadot and Substrate crates: +* 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) +* the most common types or traits, accounting for a significant fraction of the time spent in the trait system +* any examples we can find of redundant or outright wasteful trait system operations which still take non-trivial amounts of time + +Our report will also include all of the steps we performed to collect and analyze the profiling data. + +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. ### Milestone 2 — Improved trait system caching — 1 month — $10,000 -We will increase the effectiveness of caches in the Rust compiler's trait system in a variety of ways, which may include: +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. + +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: * precomputing "type flags" for type/trait system lists, not just types * introducing fast paths for common simple cases * distinguishing bounds that mention generic parameters from those that do not * removing non-global (i.e. per-inference-context) caches * replacing obsolete "freshening" with the newer "canonicalization" -* caching more of the "trait (impl) selection" process +* incorporating postprocessing (e.g. "candidate confirmation") into the cached data The above list is not exhaustive, as other opportunities may present themselves. -We will provide measurements across Polkadot and Substrate demonstrating the reduction in compile times from these changes. +We will demonstrate the reduction in compile times from these changes in a report, showing: +* overall changes in compile times across Polkadot and Substrate +* differences in the fine-grained profiling data from **Milestone 1**, in both the number of operations performed and their average duration ### Milestone 3 — Global caching for associated type projection — 1 month — $10,000 -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 advances from **Milestone 2**. +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. + +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**. -We will provide measurements across Polkadot and Substrate demonstrating the reduction in compile times from these changes. +We will demonstrate the reduction in compile times from these changes in a report, showing: +* overall changes in compile times across Polkadot and Substrate +* differences in the fine-grained profiling data from **Milestone 2**, in both the number of operations performed and their average duration ## Future Plans -Long-term, we may contribute to the Chalk project, especially its integration into the Rust compiler and the performance of the resulting system. -But in the meanwhile we will continue to look for potential improvements in the current Rust compiler codebase. +Long-term, we may contribute to the Chalk project, especially its integration into the Rust Compiler and the performance of the resulting system. +But in the meanwhile we will continue to look for potential improvements in the current Rust Compiler codebase. ## Additional Information 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. From 493e639a5d5dfee88b92bcd9ff775e2cbda2dde5 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Wed, 18 Mar 2020 18:00:38 +0200 Subject: [PATCH 3/3] Clarify that work will happen upstream (rust-lang/rust). --- grants/speculative/rust_trait_system_revamp.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/grants/speculative/rust_trait_system_revamp.md b/grants/speculative/rust_trait_system_revamp.md index 6124ae5b4..2cbe008b7 100644 --- a/grants/speculative/rust_trait_system_revamp.md +++ b/grants/speculative/rust_trait_system_revamp.md @@ -39,6 +39,8 @@ The Rust Compiler "Self-Profiling" feature is available through the nightly-only 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. +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). + We will demonstrate this new profiling data in a report, showing, for representative Polkadot and Substrate crates: * 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) * the most common types or traits, accounting for a significant fraction of the time spent in the trait system @@ -61,6 +63,8 @@ We will then address them, to increase the effectiveness of caching in the Rust The above list is not exhaustive, as other opportunities may present themselves. +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). + We will demonstrate the reduction in compile times from these changes in a report, showing: * overall changes in compile times across Polkadot and Substrate * differences in the fine-grained profiling data from **Milestone 1**, in both the number of operations performed and their average duration @@ -70,6 +74,8 @@ The Rust Compiler does not currently cache resolving associated types (i.e. "pro 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**. +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). + We will demonstrate the reduction in compile times from these changes in a report, showing: * overall changes in compile times across Polkadot and Substrate * differences in the fine-grained profiling data from **Milestone 2**, in both the number of operations performed and their average duration