Skip to content

Conversation

huonw
Copy link
Contributor

@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
Contributor Author

huonw commented Jan 27, 2014

r? @alexcrichton

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