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

std: Minimize size of panicking on wasm #49488

Merged
merged 4 commits into from
Apr 17, 2018

Commits on Apr 13, 2018

  1. std: Minimize size of panicking on wasm

    This commit applies a few code size optimizations for the wasm target to
    the standard library, namely around panics. We notably know that in most
    configurations it's impossible for us to print anything in
    wasm32-unknown-unknown so we can skip larger portions of panicking that
    are otherwise simply informative. This allows us to get quite a nice
    size reduction.
    
    Finally we can also tweak where the allocation happens for the
    `Box<Any>` that we panic with. By only allocating once unwinding starts
    we can reduce the size of a panicking wasm module from 44k to 350 bytes.
    alexcrichton committed Apr 13, 2018
    Configuration menu
    Copy the full SHA
    c3a5d6b View commit details
    Browse the repository at this point in the history
  2. Reduce the size of panics in RawVec

    Create one canonical location which panics with "capacity overflow" instead of
    having many. This reduces the size of a `panic!("{}", 1)` binary on wasm from
    34k to 17k.
    alexcrichton committed Apr 13, 2018
    Configuration menu
    Copy the full SHA
    66c5e3f View commit details
    Browse the repository at this point in the history
  3. core: Remove an implicit panic from Formatter::pad

    The expression `&s[..i]` in general can panic if `i` is out of bounds or not on
    a character boundary for a string, and this caused the codegen for
    `Formatter::pad` to be a bit larger than it otherwise needed to be. This commit
    replaces this with `s.get(..i).unwrap_or(&s)` which while having different
    behavior if `i` is out of bounds has a much smaller code footprint and otherwise
    avoids the need for `unsafe` code.
    alexcrichton committed Apr 13, 2018
    Configuration menu
    Copy the full SHA
    2bb5b5c View commit details
    Browse the repository at this point in the history
  4. std: Avoid allocating panic message unless needed

    This commit removes allocation of the panic message in instances like
    `panic!("foo: {}", "bar")` if we don't actually end up needing the message. We
    don't need it in the case of wasm32 right now, and in general it's not needed
    for panic=abort instances that use the default panic hook.
    
    For now this commit only solves the wasm use case where with LTO the allocation
    is entirely removed, but the panic=abort use case can be implemented at a later
    date if needed.
    alexcrichton committed Apr 13, 2018
    Configuration menu
    Copy the full SHA
    46d16b6 View commit details
    Browse the repository at this point in the history