Closed EFanZh closed 3 months ago
Hi @Thomasdezeeuw, this PR is ready for review, would you like to take a look at it?
I'm not sure this is worth it to be honest. The macros are already complex and this makes it even worse.
I'm also not the biggest fan of the introduced traits. I understand the thinking behind it, but again it adds more complexity.
Looking at the binary size reductions, they're not that great, less than 0.1% in most cases if I'm reading the tables correctly. Furthermore a lot of the size reduction seem to come from adding #[inline(never)]
. What are the binary size differences when only adding that?
Just coming in through some triage. It looks like we're not likely to follow this one through and the conflicts may be tricky to resolve given how things have changed in the meantime.
Thanks again for all this investigatory work @EFanZh! Please feel free to open fresh PRs with any other optimizations you find.
This PR intends to optimize binary size by avoiding passing target and level arguments if they can be determined statically.
I have rewritten the implementation of the log macros to parse each argument separately in order to map macro arguments to the underlying
__private_api::log
function arguments.Here is the binary size result tested using https://github.com/EFanZh/log/tree/binary-size-test/cargo-binstall:
Here is the runtime performance benchmark result tested using https://github.com/EFanZh/log/tree/benchmark.
Note that I have added
#[inline(never)]
to thelog
function to prevent the compiler from callinglog_impl
directly which could affect the optimization. Without#[inline(never)]
, the binary size change will be:Personally, I prefer keeping
#[inline(never)]
, since it has better binary size, and no significant performance cost.