Executable size impact #275
Labels
No labels
bug
duplicate
easy
enhancement
help wanted
invalid
question
rfc
structured-logging
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-rust-lang/log#275
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Here is a simple demo:
According to the
cargo-bloat, the code size withwarnin the release build is 1000B and withprintln- 717B. Why it impacts the size so much? Maybe this is acargo-bloatbug (yes, I'm the author)?In the real world applications, the results are even more drastic. For example, if I remove all the logging from this module the size in the release build will be reduced from 9.1KiB to 3.1KiB. It's ridiculous.
I this is a correct behavior or am I missing something?
log v0.4.1
fern v0.5.5
cargo-bloat v0.5.0
rustc 1.26.1
Log is tracking significantly more information than a println.
It's grabbing the filename, the line number, the module name, the log target, and the actual log string, rather than just the string, and performing an extra check against the global max log level: https://github.com/rust-lang-nursery/log/blob/master/src/macros.rs#L33-L51
It looks like a main function that just contains
warn!("hello world")is 204 bytes and a main function that just containsprintln!("hello world")is 77 bytes.There is some impact from the way the log macro is currently structured avoiding the construction of the Record struct cuts the size of main down to 124 bytes:
That came up as an option during the 0.4 API overhauls, and it may be worth adding back a "secret" function like log_fast for the use of the log macros.
Hmm... Interesting.
I was able to reduce the exe/crate size to the same size a bit.
Custom:
Minimal:
PS: surprisingly, removing the useless
trace!from a hot method reduced the size by 8% by itself with a default log implementation.That would make sense if the hot method was inlined in a bunch of places.
On Sun, Jun 3, 2018 at 11:16 AM Evgeniy Reizner notifications@github.com
wrote:
It was.
You can also disable specific logging levels entirely at compile time, which will remove all of the code from the resulting binary, btw: https://docs.rs/log/0.4.1/log/#compile-time-filters