Skip to content

Reduce the amount of code that fail!() creates #11841

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

Merged
merged 2 commits into from
Jan 27, 2014

Conversation

huonw
Copy link
Member

@huonw huonw commented Jan 27, 2014

In two ways:

  • for a plain fail!(a) we make the generic part of begin_unwind as small as possible (makes fn main() { fail!() } compile 2-3x faster, due to less monomorphisation bloat)
  • for fail!("format {}", "string"), we avoid touching the generics completely by doing the formatting in a specialised function, which (with optimisations) saves a function call at the call-site of fail!. (This one has significantly less benefit than the first.)

huonw added 2 commits January 27, 2014 18:03
This splits the vast majority of the code path taken by
`fail!()` (`begin_unwind`) into a separate non-generic inline(never)
function, so that uses of `fail!()` only monomorphise a small amount of
code, reducing code bloat and making very small crates compile faster.
This ends up saving a single `call` instruction in the optimised code,
but saves a few hundred lines of non-optimised IR for `fn main() {
fail!("foo {}", "bar"); }` (comparing against the minimal generic
baseline from the parent commit).
@huonw
Copy link
Member Author

huonw commented Jan 27, 2014

r? @alexcrichton

/// the actual formatting into this shared place.
#[inline(never)] #[cold]
pub fn begin_unwind_fmt(msg: &fmt::Arguments, file: &'static str, line: uint) -> ! {
begin_unwind_inner(~fmt::format(msg), file, line)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a comment referencing the comment below just explaining why it's "ok" we're doing two allocations here?

bors added a commit that referenced this pull request Jan 27, 2014
In two ways:
- for a plain `fail!(a)` we make the generic part of `begin_unwind` as small as possible (makes `fn main() { fail!() }` compile 2-3x faster, due to less monomorphisation bloat)
- for `fail!("format {}", "string")`, we avoid touching the generics completely by doing the formatting in a specialised function, which (with optimisations) saves a function call at the call-site of `fail!`. (This one has significantly less benefit than the first.)
bors added a commit that referenced this pull request Jan 27, 2014
In two ways:
- for a plain `fail!(a)` we make the generic part of `begin_unwind` as small as possible (makes `fn main() { fail!() }` compile 2-3x faster, due to less monomorphisation bloat)
- for `fail!("format {}", "string")`, we avoid touching the generics completely by doing the formatting in a specialised function, which (with optimisations) saves a function call at the call-site of `fail!`. (This one has significantly less benefit than the first.)
@bors bors closed this Jan 27, 2014
@bors bors merged commit b4bb8c0 into rust-lang:master Jan 27, 2014
@huonw huonw deleted the noinline-fail branch January 28, 2014 01:16
huonw added a commit to huonw/rust that referenced this pull request Jan 28, 2014
bors added a commit that referenced this pull request Jan 28, 2014
Follow-up to #11841 which added this function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants