-
Notifications
You must be signed in to change notification settings - Fork 56
Report creation takes a lock #126
Comments
Hey, the problem here is with I'd suggest writing your own struct FastestEyreHandlerInTheWest;
impl EyreHandler for FastestEyreHandlerInTheWest {
fn debug(
&self,
_: &(dyn StdError + 'static),
_: &mut core::fmt::Formatter<'_>,
) -> core::fmt::Result { Ok(()) }
} As for the suggestion to feature gate lib_verbosity to make it so you can continue to use Also, be fore-warned that CI is currently broken because of the syn 2.0 release and I'm working on getting that fixed in eyre. |
Over at https://github.com/akshayknarayan/color-eyre/tree/report-handler-bench I have done a little bit of benchmarking. There are 2 x 3 cases to consider: ( The benchmark function is just: fn spin_1000_[plain/with]() -> Result<(), Report> {
for _ in 0..1000 {
black_box(dummy: Ok::<_, Report>(())).wrap_err[_with](msg: eyre!("error"))?;
}
Ok(())
} Some initial results below:
It seems clear that the handler matters, but that using |
Issue can be closed, fixed by #93. |
I have some code that looks roughly like this:
This is bad for performance because it turns out error creation (
eyre!
) takes a lock when it callsstd::env::var
here: https://github.com/yaahc/color-eyre/blob/4a7b4d6988c6b0da5e04e29c9d6e10595b5dc302/src/config.rs#L1208Instead, the better way is probably like this:
I'd like to suggest that either:
eyre!
andwrap_err()
that makes it clear thateyre!
is not free and thatwrap_err_with
should be used in most cases.lib_verbosity
become feature-gated (perhaps returningVerbosity::Minimal
by default), so thateyre!
is cheap to call.Thanks!
The text was updated successfully, but these errors were encountered: