Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MIR-only rlibs #119017

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

MIR-only rlibs #119017

wants to merge 1 commit into from

Conversation

saethlin
Copy link
Member

@saethlin saethlin commented Dec 16, 2023

Status update: The strategy I implemented in this PR is to make builds of non-rlib crates monomorphize everything they need. I was quite thorough about this and had to add a handful of hacks to make it happen.

But I now believe that was a mistake, because of how it breaks proc-macro crates. I think those crates can only work if they are able to cooperate with the compiler correctly to share types across the proc-macro bridge. Currently this is achieved by linking both against the libstd dylib, which contains monomorphizations of the allocator shims and probably a handful of other things. So in order to make this work, I at least need to figure out how to make the compiler expose all the monomorphizations of the standard library, and make the proc-macro crates link against those instead of monomorphizing their own.


Originally I was just trying to imitate MIR-only rlibs with -Zcross-crate-inline-threshold=yes, but I think I have enough skill to actually implement the behavior. We shall see.

At time of writing, set RUSTFLAGS=-Zmir-only-libs and if each session that Cargo kicks off only compiles an rlib or an executable, every rlib should contain only MIR and the build should work. Any other configuration probably explodes unceremoniously.

r? @ghost

@saethlin saethlin added the S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. label Dec 16, 2023
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Dec 16, 2023
@saethlin
Copy link
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Dec 16, 2023
@bors
Copy link
Contributor

bors commented Dec 16, 2023

⌛ Trying commit d9e0f19 with merge f4568e9...

bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 16, 2023
[perf experiment] (crudely) implement MIR-only rlibs

I realized that `-Zcross-crate-inline-threshold=always` is now basically MIR-only rlibs. So if nothing else, this is an easy way to study the perf implications of such a design.

Pondering this because it would be neat to codegen MIR for the standard library differently based on build flags passed by an end user.

r? `@ghost`
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Dec 16, 2023

☀️ Try build successful - checks-actions
Build commit: f4568e9 (f4568e9b4c437be978fa03a4b3ebc07f5800c83d)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (f4568e9): comparison URL.

Overall result: ❌✅ regressions and improvements - ACTION NEEDED

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
156.8% [0.3%, 3121.3%] 166
Regressions ❌
(secondary)
1167.6% [0.1%, 21506.7%] 116
Improvements ✅
(primary)
-0.8% [-6.6%, -0.2%] 47
Improvements ✅
(secondary)
-1.8% [-11.6%, -0.1%] 79
All ❌✅ (primary) 122.0% [-6.6%, 3121.3%] 213

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
32.5% [0.4%, 448.7%] 179
Regressions ❌
(secondary)
27.0% [0.7%, 183.5%] 151
Improvements ✅
(primary)
-2.8% [-5.1%, -0.5%] 2
Improvements ✅
(secondary)
-8.9% [-9.2%, -8.6%] 3
All ❌✅ (primary) 32.1% [-5.1%, 448.7%] 181

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
185.0% [0.7%, 2991.0%] 151
Regressions ❌
(secondary)
1094.9% [1.3%, 18459.6%] 114
Improvements ✅
(primary)
-1.6% [-1.6%, -1.6%] 1
Improvements ✅
(secondary)
-3.5% [-5.0%, -2.1%] 5
All ❌✅ (primary) 183.8% [-1.6%, 2991.0%] 152

Binary size

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
73.5% [0.0%, 423.5%] 134
Regressions ❌
(secondary)
440.4% [0.1%, 4194.7%] 52
Improvements ✅
(primary)
-18.0% [-49.7%, -0.8%] 17
Improvements ✅
(secondary)
-32.3% [-50.4%, -0.4%] 73
All ❌✅ (primary) 63.2% [-49.7%, 423.5%] 151

Bootstrap: 672.461s -> 1381.575s (105.45%)
Artifact size: 312.46 MiB -> 339.60 MiB (8.69%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Dec 16, 2023
@saethlin saethlin force-pushed the mir-only-rlibs branch 2 times, most recently from 741a7a7 to 9fc5b9f Compare January 10, 2024 04:56
@saethlin saethlin changed the title [perf experiment] (crudely) implement MIR-only rlibs MIR-only rlibs Jan 10, 2024
@rustbot
Copy link
Collaborator

rustbot commented Jan 10, 2024

Failed to set assignee to ghost: invalid assignee

Note: Only org members with at least the repository "read" role, users with write permissions, or people who have commented on the PR may be assigned.

@saethlin saethlin removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 10, 2024
@bors
Copy link
Contributor

bors commented Jan 11, 2024

☔ The latest upstream changes (presumably #119843) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jan 11, 2024
@oli-obk
Copy link
Contributor

oli-obk commented Feb 13, 2024

The MCP has been accepted

@saethlin
Copy link
Member Author

👍

This PR is still not really mergeable because it breaks proc macros. I think because I'm monomorphizing the allocator shims wrong.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Mar 12, 2024

☔ The latest upstream changes (presumably #121644) made this pull request unmergeable. Please resolve the merge conflicts.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Mar 19, 2024

☔ The latest upstream changes (presumably #122037) made this pull request unmergeable. Please resolve the merge conflicts.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Mar 21, 2024

☔ The latest upstream changes (presumably #122568) made this pull request unmergeable. Please resolve the merge conflicts.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Apr 30, 2024

☔ The latest upstream changes (presumably #124558) made this pull request unmergeable. Please resolve the merge conflicts.

@Dylan-DPC Dylan-DPC removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Aug 2, 2024
@joshtriplett
Copy link
Member

How feasible would it be to opt into a MIR-only rlib for a particular dependency? That might sidestep some of the difficulties associated with using it everywhere, while allowing large crates with very few items used to opt into it to reduce how much gets compiled.

@saethlin
Copy link
Member Author

while allowing large crates with very few items used to opt into it to reduce how much gets compiled.

If you want to try using this to cut down build times, you can investigate whether it would help by setting -Zcross-crate-inline-threshold=always for just that crate. I suspect that doing so will regress build times.

But thanks for pinging this PR! I'll try to rebase it up soon just to keep it alive.

@joshtriplett
Copy link
Member

@saethlin

I tested this on one of my projects:

Baseline:

Finished release profile [optimized] target(s) in 10m 31s

With the three biggest crates in the dependency tree (which I use a tiny fraction of the items of) using -Zcross-crate-inline-threshold=always:

Finished release profile [optimized] target(s) in 6m 31s

@saethlin
Copy link
Member Author

saethlin commented Oct 17, 2024

Note that CI may pass, because in line with:

That might sidestep some of the difficulties associated with using it everywhere

I removed the line that was making the compiler bootstrap with -Zmir-only-rlibs set. So the option is now untested in CI, I think.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@joshtriplett
Copy link
Member

joshtriplett commented Oct 18, 2024

Update (same project, flags applied to the same set of 3 large crates with most items unused):

Build Time
Baseline 10m 30s
-Zcross-crate-inline-threshold=always 6m 12s
-Zcross-crate-inline-threshold=always -Zmir-opt-level=0 5m 34s
-Zcross-crate-inline-threshold=always -Zmir-opt-level=1 5m 48s
-Zcross-crate-inline-threshold=always -Zinline-mir=no 5m 51s

@bors
Copy link
Contributor

bors commented Nov 10, 2024

☔ The latest upstream changes (presumably #132173) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Nov 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants