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.
This commit is contained in:
parent
99d4886ead
commit
c3a5d6b130
20 changed files with 205 additions and 45 deletions
|
@ -139,10 +139,10 @@ pub fn __rust_begin_short_backtrace<F, T>(f: F) -> T
|
|||
/// Controls how the backtrace should be formatted.
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||
pub enum PrintFormat {
|
||||
/// Show all the frames with absolute path for files.
|
||||
Full = 2,
|
||||
/// Show only relevant data from the backtrace.
|
||||
Short = 3,
|
||||
Short = 2,
|
||||
/// Show all the frames with absolute path for files.
|
||||
Full = 3,
|
||||
}
|
||||
|
||||
// For now logging is turned off by default, and this function checks to see
|
||||
|
@ -150,11 +150,10 @@ pub enum PrintFormat {
|
|||
pub fn log_enabled() -> Option<PrintFormat> {
|
||||
static ENABLED: atomic::AtomicIsize = atomic::AtomicIsize::new(0);
|
||||
match ENABLED.load(Ordering::SeqCst) {
|
||||
0 => {},
|
||||
0 => {}
|
||||
1 => return None,
|
||||
2 => return Some(PrintFormat::Full),
|
||||
3 => return Some(PrintFormat::Short),
|
||||
_ => unreachable!(),
|
||||
2 => return Some(PrintFormat::Short),
|
||||
_ => return Some(PrintFormat::Full),
|
||||
}
|
||||
|
||||
let val = match env::var_os("RUST_BACKTRACE") {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue