Use non-generic inner function for pointer formatting #91266
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, despite the implementation being type-unaware,
fmt::Pointer
's implementation for*const T
in monomorphized. This affects:fmt::Debug
for*const T
fmt::Debug
for*mut T
fmt::Pointer
for*const T
fmt::Pointer
for*mut T
And since the implementation is non-trivial, this results in a large amount of LLVM bitcode being generated. For example, with a large bindgen project with Debug implementations enabled, it will generate a lot of calls to
fmt::Debug for *const T
, which in turn will perform codegen for a copy of this function for every type.For example, in a real-world bindgen'd header I've been testing with (4,189,245 lines of bindgen Rust with layout tests disabled) the difference between a slightly old nightly (
rustc 1.58.0-nightly (e249ce6b2 2021-10-30)
) and this PR:Nightly (Click to Expand)
This PR (Click to Expand)
Output generated using
cargo llvm-lines
version 0.4.12.Summary of differences:
*const T as fmt::Pointer
LLVM linesnightly
This results in a pretty noticeable as the majority of rustc's time is spent in either codegen or LLVM, in this case, and is significantly improved by disabling derives for
fmt::Debug
, as it prevents generating all this LLVM IR to be handled.Here's a run time comparison with nightly on the same codebase (commit 454cc5f built from source vs 37c8f25 from my PR built from source):
nightly (Click to Expand)
This PR (Click to Expand)
(6.34% decrease in runtime, results are consistent across multiple runs)