Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

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

Open
deifactor opened this issue Dec 28, 2023 · 0 comments

Comments

@deifactor
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant