Stream: cranelift

Topic: logging


view this post on Zulip Andrew Brown (Mar 23 2021 at 16:45):

@Chris Fallin, @Benjamin Bouvier: I am surprised that https://github.com/bytecodealliance/wasmtime/pull/2755 is needed... I haven't looked at the implementation of debug! but I assumed that the point of having such a macro is that the expressions passed to the logger are not evaluated _unless_ logging is enabled. Why do we have to have another check around that?!?

This logging step may be quite expensive, since rendering the VCode into strings has never been optimized at all and is using pretty naive string concatenation. Removing it is a clear compile times...

view this post on Zulip Chris Fallin (Mar 23 2021 at 16:46):

Indeed, I was surprised too -- will be curious to know more details about @Benjamin Bouvier 's environment (ie loggingg module setup)

view this post on Zulip Chris Fallin (Mar 23 2021 at 16:46):

if it is the case that args are always evaluated, or we can't rely on them not being so, then we should audit a bunch of hot paths!

view this post on Zulip Chris Fallin (Mar 23 2021 at 16:47):

(a lot of debug logging just prints primitive locals that exist anyway, so I imagine there's no overhead there aside from the do-I-log branch; but there may be other cases where we explicitly build a string in a call somewhere)

view this post on Zulip Andrew Brown (Mar 23 2021 at 16:56):

yes, exactly!

view this post on Zulip Alex Crichton (Mar 23 2021 at 16:58):

@Andrew Brown @Chris Fallin regardless of logging level the arguments to the logging macro are always evaluated

view this post on Zulip Alex Crichton (Mar 23 2021 at 16:59):

regardless of whichever logging crate you're using I believe

view this post on Zulip Chris Fallin (Mar 23 2021 at 16:59):

@Alex Crichton that is very much a TIL for me and I now know what I'm doing with high-ish priority. Thanks :-)

view this post on Zulip Andrew Brown (Mar 23 2021 at 16:59):

That seems broken, though... most of us expect logging to be lazily evaluated?

view this post on Zulip Alex Crichton (Mar 23 2021 at 17:00):

wait no, don't quote me on this

view this post on Zulip Andrew Brown (Mar 23 2021 at 17:00):

@Alex Crichton, is this something that could/should be fixed in log? Or does it have to be this way?

view this post on Zulip Alex Crichton (Mar 23 2021 at 17:00):

the source disagrees with me

view this post on Zulip Andrew Brown (Mar 23 2021 at 17:00):

do you have the link?

view this post on Zulip Alex Crichton (Mar 23 2021 at 17:01):

@Chris Fallin no I am wrong

view this post on Zulip Alex Crichton (Mar 23 2021 at 17:01):

arguments are not evaluated

view this post on Zulip Alex Crichton (Mar 23 2021 at 17:01):

so this is probably the tokio bug and a crate that wasn't updated

view this post on Zulip Alex Crichton (Mar 23 2021 at 17:01):

@Andrew Brown I just checked locally and log::debug!("{:?}", println!("")); doesn't print anything

view this post on Zulip Alex Crichton (Mar 23 2021 at 17:01):

so arguments aren't evaluated unless the log level is enabled

view this post on Zulip Alex Crichton (Mar 23 2021 at 17:02):

sorry I thought it was the other way around which is why I approved...

view this post on Zulip Andrew Brown (Mar 23 2021 at 17:02):

phew... my faith in log is restored

view this post on Zulip Chris Fallin (Mar 23 2021 at 17:02):

Phew. Crisis averted.

view this post on Zulip Andrew Brown (Mar 23 2021 at 17:02):

but does that mean that @Benjamin Bouvier's PR was necessary?

view this post on Zulip Chris Fallin (Mar 23 2021 at 17:03):

Well, it's possible that others may be running with older (buggy) logging environments for which this is not true, I suppose

view this post on Zulip Alex Crichton (Mar 23 2021 at 17:03):

it means it shouldn't be necessary, no

view this post on Zulip Andrew Brown (Mar 23 2021 at 17:03):

yeah

view this post on Zulip Andrew Brown (Mar 23 2021 at 17:03):

Alex, what's the tokio bug?

view this post on Zulip Alex Crichton (Mar 23 2021 at 17:04):

https://github.com/tokio-rs/tracing/issues/1249

Bug Report Version ├── tracing-subscriber v0.2.15 │ ├── tracing v0.1.22 () │ ├── tracing-log v0.1.1 │ │ └── tracing-core v0.1.17 () Platform Linux finknottle 5.8.0-43-generic #49~20.04.1-Ubuntu SMP...

view this post on Zulip Andrew Brown (Mar 23 2021 at 17:07):

cool, thanks

view this post on Zulip Benjamin Bouvier (Mar 23 2021 at 17:19):

oh really? i just spent some time looking at the log's code and concluded that it was necessary... let me back it up

view this post on Zulip lqd (Mar 23 2021 at 17:42):

I was equally surprised by this, the arguments are not evaluated if the max_level is correctly set

view this post on Zulip lqd (Mar 23 2021 at 17:43):

which could happen if the buggy version of tracing-subscriber is used, or if some incorrect code is used to set up the loggers

view this post on Zulip lqd (Mar 23 2021 at 17:48):

to make sure, I've added panics at the same places the PR changes things:

view this post on Zulip Benjamin Bouvier (Mar 23 2021 at 18:20):

It might have been a red herring then: we're using tracing-subscriber, as well as another small log wrapper that might be doing something silly. I'll confirm, but then we can probably revert the change I've made.

view this post on Zulip Benjamin Bouvier (Mar 23 2021 at 19:02):

Yep, that was it: we were using a default ctor of tracing_subscriber which sets the max_level to LevelFilter::Max, by default -_-'

view this post on Zulip Benjamin Bouvier (Mar 23 2021 at 19:02):

Good thing that the log macros are actually sane, and that we don't need to audit the full code base for other log uses!

view this post on Zulip Pat Hickey (Mar 25 2021 at 18:14):

its a bummer that the log ecosystem and tracing-subscriber dont work together perfectly well, but fastly uses tracing-subscriber in a lot of contexts and i expect many other users will as well, so its worthwhile to make sure we are optimized properly for using tracing-subscriber as well as the usual env_logger or equivelant

view this post on Zulip Chris Fallin (Mar 25 2021 at 18:22):

@Pat Hickey we have a nice solution now suggested by Alex in #2758 -- agreed that we want to avoid performance footguns like this lest we drive folks away thinking our backend is too slow


Last updated: Nov 22 2024 at 17:03 UTC