cranelift: Use a deferred display mechanism instead of log_enabled!#2758
cranelift: Use a deferred display mechanism instead of log_enabled!#2758bnjbvr merged 1 commit intobytecodealliance:mainfrom
log_enabled!#2758Conversation
cfallin
left a comment
There was a problem hiding this comment.
Thanks for the investigation!
I do wonder if there's a better way to remove the footgun danger here: while the issue ultimately was in the faulty logging configuration in a particular embedding, it's plausible that someone else might have the same setup issues and then conclude that Cranelift is unusably slow. That's kind-of our problem, too, if only indirectly.
Would it make sense to centralize all of our logging in our own macro that wraps log's APIs, but does the log_enabled check? Or checks some other global that we control? That's definitely taking on a responsibility that should be covered by the logging infra but maybe we can make it safer...?
Random (cute) idea: how about we add a On the other hand, forcing users to not enable |
Interesting idea -- yes, that could definitely make sense. IIRC, though, wasn't the issue here that the logging level was high/max in some internal setting, but logs were not actually being written somewhere? |
|
Yeah, you're right. Trying to get to the bottom of this, here's what's happening: the
Now, the On the other hand, the I don't have all the background for the What do you all think about it? (Alternatives: make the vcode string rendering not so dramatically slow, use our own log macros that use |
|
Another possible alternative would be auditing to ensure that the argument evaluation itself is not expensive. There's not a great way to do this all the time but the theory is that you can avoid speeding things up by deferring actual formatting to when requested. (e.g. have one-off structs with The separation was indeed for performance, where the |
|
Wrapping everything in a struct ( Alternately, I am OK with staying with the status quo ( == current |
|
To clarify, though, the exact struct would look more like: struct DeferredDisplay<F>(F);
impl<F, R> fmt::Display for DeferredDisplay<F>
where
F: Fn() -> R,
R: fmt::Display,
{
// ..
}notably the closure would bake in "only run this when |
|
Fun idea, I've implemented it, thanks Alex! Care to have another look, please? |
log_enabled!
This reverts commit 49ef2c6. It was
found that this isn't needed as long as the user code correctly sets the
log's maximum logging level with
log::set_max_value.