eyre-rs / color-eyre

Custom hooks for colorful human oriented error reports via panics and the eyre crate
Other
960 stars 56 forks source link

First eyre::Result::Err variant is slow to construct if backtraces are enabled #148

Open deifactor opened 11 months ago

deifactor commented 11 months ago

With color-eyre 0.6.2 and RUST_BACKTRACE=1

fn main() -> Result<()> {
    color_eyre::install()?;
    let now = Instant::now();
    let _ = eyre::eyre!("one");
    println!("first error: {:?}", Instant::now() - now);
    let now = Instant::now();
    let _ = eyre::eyre!("two");
    println!("second error: {:?}", Instant::now() - now);
    Ok(())
}

cargo run --release gives

first error: 6.476077ms
second error: 35.841µs

Getting rid of the color_eyre::install() call or not setting RUST_BACKTRACE gets rid of this behavior. This bit me because I'm writing a music player and the decoder library I'm using signals EOF by constructing an Err, so I wind up underflowing my buffer on the first EOF I got. I can work around this by just constructing and throwing away an err variant; if this isn't fixable, IMO it should be documented.