Closed pwoolcoc closed 4 weeks ago
@EFanZh I know you are/were interested in reducing the code size of log
, do you want to check this pr for code size changes?
Can you remove the
line!
andfile!
macros?
Done!
@EFanZh I know you are/were interested in reducing the code size of
log
, do you want to check this pr for code size changes?
@Thomasdezeeuw Yes, I think I can have the result in a few days after my comment being addressed.
I have tested this PR on my project, I see an observable size increasing of the result binary. It seems that currently the compiler can’t optimize this implementation well: https://godbolt.org/z/1E4fWKv34.
I have tested this PR on my project, I see an observable size increasing of the result binary. It seems that currently the compiler can’t optimize this implementation well: https://godbolt.org/z/1E4fWKv34.
I tried adding #[inline]
, which makes it a little better, but it's still more code than the file!
& line!
variant.
I think the problem is that additional function calls somehow prevent the compiler from treating constant values as static values: https://godbolt.org/z/57K9hdEcc.
I think the problem is that additional function calls somehow prevents the compiler from treating constant values as static values: https://godbolt.org/z/57K9hdEcc.
I don't really have a good solution for this. Maybe it's worth opening a discussion on rustc's Zullip? Or an issue in the rustc tracker?
@Thomasdezeeuw I have submitted an issue here: https://github.com/rust-lang/rust/issues/118557.
This seems useful for helpers marked with #[track_caller]
that do logging internally to opt-in or out of having the caller location tagged in the log line. What would the apetite be for using Location:caller
vs file!()
, line!()
conditionally based on an argument to the macros?
If there's interest I can try to get a PR up
Maybe we can change the __private_api::log
function to accept &std::panic::Location
? Maybe that will not increase the binary size?
I'm not sure introducing complexity with a conditional would be the best way forward, but we can experiment with it.
I've re-opened this as #633 to get the ball rolling again. We can still find our way back to the discussion here if necessary.
Thanks for the original PR @pwoolcoc!
At some point I deleted the fork that I used to open https://github.com/rust-lang/log/pull/410, so this is just the updated version of that PR. I have removed the feature gate for this, as it was suggested that since the MSRV is now 1.60.0, this feature should be unconditional.