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

Merged
merged 1 commit into from Oct 26, 2018

Conversation

Projects
None yet
9 participants
@nnethercote
Contributor

nnethercote commented Oct 25, 2018

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%.

@rust-highfive

This comment has been minimized.

Collaborator

rust-highfive commented Oct 25, 2018

r? @pnkfelix

(rust_highfive has picked a reviewer for you, use r? to override)

@nnethercote

This comment has been minimized.

Contributor

nnethercote commented Oct 25, 2018

Here are the instruction count improvements that exceed 1%.

style-servo-debug
	avg: -2.1%	min: -3.2%	max: 0.4%
webrender-debug
	avg: -1.4%	min: -2.9%	max: -0.1%
regression-31157-debug
	avg: -1.6%	min: -2.7%	max: -0.4%
issue-46449-debug
	avg: -2.4%	min: -2.7%	max: -1.2%
cargo-debug
	avg: -1.8%	min: -2.4%	max: -0.1%
piston-image-debug
	avg: -1.2%	min: -2.3%	max: -0.2%
regex-debug
	avg: -1.4%	min: -2.3%	max: -0.1%
crates.io-debug
	avg: -1.3%	min: -2.3%	max: -0.1%
syn-debug
	avg: -1.3%	min: -2.2%	max: -0.1%
clap-rs-debug
	avg: -1.4%	min: -2.2%	max: 0.2%
helloworld-check
	avg: -1.9%	min: -2.0%	max: -1.7%
encoding-debug
	avg: -1.1%	min: -1.9%	max: -0.2%
deeply-nested-debug
	avg: -1.7%	min: -1.9%	max: -1.3%
sentry-cli-debug
	avg: -1.0%	min: -1.9%	max: -0.0%
unify-linearly-check
	avg: -1.3%	min: -1.8%	max: -0.9%
deeply-nested-check
	avg: -1.2%	min: -1.8%	max: -0.8%
ctfe-stress-debug
	avg: 0.2%?	min: -1.3%?	max: 1.7%?
tokio-webpush-simple-debug
	avg: -1.2%	min: -1.6%	max: -0.1%
ctfe-stress-check
	avg: -0.5%?	min: -1.6%?	max: 0.7%?
ripgrep-debug
	avg: -0.7%	min: -1.4%	max: 0.1%
ctfe-stress-opt
	avg: -0.9%?	min: -1.4%?	max: -0.4%?
coercions-debug
	avg: -0.5%?	min: -1.3%?	max: -0.0%?
issue-46449-check
	avg: -1.1%	min: -1.3%	max: -0.8%
deeply-nested-opt
	avg: -1.1%	min: -1.3%	max: -0.9%
webrender-opt
	avg: -0.9%	min: -1.2%	max: -0.1%
issue-46449-opt
	avg: -0.9%	min: -1.1%	max: -0.7%
clap-rs-opt
	avg: -0.7%	min: -1.1%	max: -0.1%
tokio-webpush-simple-opt
	avg: -0.7%	min: -1.0%	max: -0.2%
style-servo-opt
	avg: -0.7%	min: -1.0%	max: 0.1%
coercions-check
	avg: -0.4%?	min: -1.0%?	max: 0.0%?
@@ -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);

This comment has been minimized.

@bjorn3

bjorn3 Oct 25, 2018

Contributor

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); }
    ()
};

This comment has been minimized.

@nikic

nikic Oct 25, 2018

Contributor

librustc also has a static_assert! macro for this kind of pattern.

This comment has been minimized.

@bjorn3

bjorn3 Oct 25, 2018

Contributor

Didn't know about that.

static_assert!(STATMENT_IS_AT_MOST_56_BYTES: std::mem::size_of::<Statement<'_>>() <= 56usize);
@nagisa

This comment has been minimized.

Contributor

nagisa commented Oct 25, 2018

This is another instance of #54526.

It is nice to see there is an effort to add a test for this :)

r=me when debug_assert! becomes a static_assert! or a #[test].

@nnethercote

This comment has been minimized.

Contributor

nnethercote commented Oct 25, 2018

This is another instance of #54526.

Oh geez. I'd forgotten about that. Interestingly, that one didn't give an instruction count improvement, but this one does. Not sure why.

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%.
@nnethercote

This comment has been minimized.

Contributor

nnethercote commented Oct 25, 2018

I've updated to use static_assert!.

@Mark-Simulacrum

This comment has been minimized.

Member

Mark-Simulacrum commented Oct 25, 2018

@bors r=nagisa

@bors

This comment has been minimized.

Contributor

bors commented Oct 25, 2018

📌 Commit 38d9277 has been approved by nagisa

kennytm added a commit to kennytm/rust that referenced this pull request Oct 26, 2018

Rollup merge of rust-lang#55346 - nnethercote:shrink-StatementKind, r…
…=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%.

kennytm added a commit to kennytm/rust that referenced this pull request Oct 26, 2018

Rollup merge of rust-lang#55346 - nnethercote:shrink-StatementKind, r…
…=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%.

bors added a commit that referenced this pull request Oct 26, 2018

Auto merge of #55371 - kennytm:rollup, r=kennytm
Rollup of 16 pull requests

Successful merges:

 - #53996 ([CI] Run a `thumbv7m-none-eabi` binary using `qemu-system-arm` [IRR-2018-embedded])
 - #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)
 - #55262 (Change the ICE from #55223 to a hard error)
 - #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)
 - #55325 (Fix link to macros chapter)
 - #55343 (rustbuild: fix remap-debuginfo when building a release)
 - #55346 (Shrink `Statement`.)
 - #55358 (Remove redundant clone (2))
 - #55363 (Bump cargo-vendor version to 0.1.17)

bors added a commit that referenced this pull request Oct 26, 2018

Auto merge of #55371 - kennytm:rollup, r=kennytm
Rollup of 15 pull requests

Successful merges:

 - #53996 ([CI] Run a `thumbv7m-none-eabi` binary using `qemu-system-arm` [IRR-2018-embedded])
 - #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)
 - #55262 (Change the ICE from #55223 to a hard error)
 - #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)
 - #55325 (Fix link to macros chapter)
 - #55343 (rustbuild: fix remap-debuginfo when building a release)
 - #55346 (Shrink `Statement`.)
 - #55358 (Remove redundant clone (2))

kennytm added a commit to kennytm/rust that referenced this pull request Oct 26, 2018

Rollup merge of rust-lang#55346 - nnethercote:shrink-StatementKind, r…
…=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%.

bors added a commit that referenced this pull request Oct 26, 2018

Auto merge of #55382 - kennytm:rollup, r=kennytm
Rollup of 19 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)
 - #55262 (Change the ICE from #55223 to a hard error)
 - #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))
 - #55363 (Bump cargo-vendor version to 0.1.17)
 - #55370 (Update mailmap for estebank)
 - #55375 (Typo fixes in configure_cmake comments)
 - #55378 (rustbuild: use configured linker to build boostrap)

Failed merges:

r? @ghost

bors added a commit that referenced this pull request Oct 26, 2018

Auto merge of #55382 - kennytm:rollup, r=kennytm
Rollup of 19 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)
 - #55262 (Change the ICE from #55223 to a hard error)
 - #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)

kennytm added a commit to kennytm/rust that referenced this pull request Oct 26, 2018

Rollup merge of rust-lang#55346 - nnethercote:shrink-StatementKind, r…
…=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%.

bors added a commit that referenced this pull request Oct 26, 2018

Auto merge of #55382 - kennytm:rollup, r=kennytm
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)

@bors bors merged commit 38d9277 into rust-lang:master Oct 26, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@nnethercote nnethercote deleted the nnethercote:shrink-StatementKind branch Oct 28, 2018

bors added a commit that referenced this pull request Oct 29, 2018

Auto merge of #55405 - alexcrichton:beta-next, r=<try>
[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

bors added a commit that referenced this pull request Oct 29, 2018

Auto merge of #55405 - alexcrichton:beta-next, r=pietroalbini
[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

bors added a commit that referenced this pull request Oct 29, 2018

Auto merge of #55405 - alexcrichton:beta-next, r=pietroalbini
[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);

This comment has been minimized.

@RalfJung

RalfJung Nov 1, 2018

Member

Why is this inside some random function, as opposed to, say, next to enum Statement?

This comment has been minimized.

@nnethercote

nnethercote Nov 4, 2018

Contributor

I didn't realize static_assert! was valid at the top level. I'll fix it in another PR, thanks for the tip.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment