-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Shrink Statement
.
#55346
Shrink Statement
.
#55346
Conversation
r? @pnkfelix (rust_highfive has picked a reviewer for you, use r? to override) |
Here are the instruction count improvements that exceed 1%.
|
src/librustc/mir/mod.rs
Outdated
@@ -1674,6 +1674,10 @@ impl<'tcx> Statement<'tcx> { | |||
/// Changes a statement to a nop. This is both faster than deleting instructions and avoids | |||
/// invalidating statement indices in `Location`s. | |||
pub fn make_nop(&mut self) { | |||
// `Statement` contributes significantly to peak memory usage. Make | |||
// sure it doesn't get bigger. | |||
debug_assert!(mem::size_of::<Statement<'_>>() <= 56usize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use a static assert instead:
#![feature(const_transmute, const_let)]
use std::mem;
#[allow(dead_code)]
const ASSERT_STATMENT_IS_56_BYTES: () = {
unsafe { mem::transmute::<_, [u8; 56]>(Statement::Nop); }
()
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
librustc also has a static_assert!
macro for this kind of pattern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't know about that.
static_assert!(STATMENT_IS_AT_MOST_56_BYTES: std::mem::size_of::<Statement<'_>>() <= 56usize);
This is another instance of #54526. It is nice to see there is an effort to add a test for this :) r=me when |
Oh geez. I'd forgotten about that. Interestingly, that one didn't give an instruction count improvement, but this one does. Not sure why. |
This commit reduces the size of `Statement` from 80 bytes to 56 bytes on 64-bit platforms, by boxing the `AscribeUserType` variant of `StatementKind`. This change reduces instruction counts on most benchmarks by 1--3%.
6cca15c
to
38d9277
Compare
I've updated to use |
@bors r=nagisa |
📌 Commit 38d9277 has been approved by |
…=nagisa Shrink `Statement`. This commit reduces the size of `Statement` from 80 bytes to 56 bytes on 64-bit platforms, by boxing the `AscribeUserType` variant of `StatementKind`. This change reduces instruction counts on most benchmarks by 1--3%.
…=nagisa Shrink `Statement`. This commit reduces the size of `Statement` from 80 bytes to 56 bytes on 64-bit platforms, by boxing the `AscribeUserType` variant of `StatementKind`. This change reduces instruction counts on most benchmarks by 1--3%.
Rollup of 21 pull requests Successful merges: - #54816 (Don't try to promote already promoted out temporaries) - #54824 (Cleanup rustdoc tests with `@!has` and `@!matches`) - #54921 (Add line numbers option to rustdoc) - #55167 (Add a "cheap" mode for `compute_missing_ctors`.) - #55258 (Fix Rustdoc ICE when checking blanket impls) - #55264 (Compile the libstd we distribute with -Ccodegen-unit=1) - #55271 (Unimplement ExactSizeIterator for MIR traversing iterators) - #55292 (Macro diagnostics tweaks) - #55298 (Point at macro definition when no rules expect token) - #55301 (List allowed tokens after macro fragments) - #55302 (Extend the impl_stable_hash_for! macro for miri.) - #55325 (Fix link to macros chapter) - #55343 (rustbuild: fix remap-debuginfo when building a release) - #55346 (Shrink `Statement`.) - #55358 (Remove redundant clone (2)) - #55370 (Update mailmap for estebank) - #55375 (Typo fixes in configure_cmake comments) - #55378 (rustbuild: use configured linker to build boostrap) - #55379 (validity: assert that unions are non-empty) - #55383 (Use `SmallVec` for the queue in `coerce_unsized`.) - #55391 (bootstrap: clean up a few clippy findings)
[beta]: Prepare the 1.31.0 beta release * Update to Cargo's branched 1.31.0 branch * Update the channel to `beta` Rolled up beta-accepted PRs: * #55362: Remove `cargo new --edition` from release notes. * #55325: Fix link to macros chapter * #55358: Remove redundant clone (2) * #55346: Shrink `Statement`. * #55274: Handle bindings in substructure of patterns with type ascriptions * #55297: Partial implementation of uniform paths 2.0 to land before beta * #55192: Fix ordering of nested modules in non-mod.rs mods * #55185: path suggestions in Rust 2018 should point out the change in semantics * #55423: back out bogus `Ok`-wrapping suggestion on `?` arm type mismatch Note that **this does not update the bootstrap compiler** due to #55404
@@ -1674,6 +1674,10 @@ impl<'tcx> Statement<'tcx> { | |||
/// Changes a statement to a nop. This is both faster than deleting instructions and avoids | |||
/// invalidating statement indices in `Location`s. | |||
pub fn make_nop(&mut self) { | |||
// `Statement` contributes significantly to peak memory usage. Make | |||
// sure it doesn't get bigger. | |||
static_assert!(STATEMENT_IS_AT_MOST_56_BYTES: mem::size_of::<Statement<'_>>() <= 56); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this inside some random function, as opposed to, say, next to enum Statement
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't realize static_assert!
was valid at the top level. I'll fix it in another PR, thanks for the tip.
This commit reduces the size of
Statement
from 80 bytes to 56 bytes on64-bit platforms, by boxing the
AscribeUserType
variant ofStatementKind
.This change reduces instruction counts on most benchmarks by 1--3%.