-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Collect VTable stats & add -Zprint-vtable-sizes
#112400
Conversation
r? @b-naber (rustbot has picked a reviewer for you, use r? to override) |
…=Nilstrieb Don't `use compile_error as print` I've spent **1.5 hours** debugging this while trying to compile rust-lang#112400, if we use `compile_error!`, we should not just forward user input to it, but issue a reasonable error message. The better solution would be to use a lint like `clippy::print_stdout`, but since we don't have clippy in CI, let's at least make the macro error better. Also note that some functions called here actually do use `println` (see for example `print_type_sizes` function).
ff566a0
to
88095f5
Compare
88095f5
to
f2545fb
Compare
So, status update:
With this I think this is ready for review. Some things we might want to fix:
|
let existential_trait_ref = trait_ref.map_bound(|trait_ref| { | ||
ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref) | ||
}); | ||
|
||
// Lookup the shape of vtable for the trait. | ||
let own_existential_entries = | ||
tcx.own_existential_vtable_entries(existential_trait_ref.def_id()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let existential_trait_ref = trait_ref.map_bound(|trait_ref| { | |
ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref) | |
}); | |
// Lookup the shape of vtable for the trait. | |
let own_existential_entries = | |
tcx.own_existential_vtable_entries(existential_trait_ref.def_id()); | |
// Lookup the shape of vtable for the trait. | |
let own_existential_entries = | |
tcx.own_existential_vtable_entries(trait_ref.def_id()); |
size_words_without_upcasting: unupcasted_cost, | ||
size_words_with_upcasting: unupcasted_cost + upcast_cost, | ||
difference_words: upcast_cost, | ||
difference_percent: upcast_cost as f64 / unupcasted_cost as f64 * 100., |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why isnt this (size_words_without_upcasting + size_words_with_upcasting) / size_words_without_upcasting
... not sure if i totally understand the math here, that could use some explanation i think 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nvm, I think I get it. This creates a "how much % larger is the new vtable compared to the old table". could use doc tho
let own_entries = own_existential_entries.iter().copied().map(|_def_id| { | ||
// The original code here ignores the method if its predicates are impossible. | ||
// We can't really do that as, for example, all not trivial bounds on generic | ||
// parameters are impossible (since we don't know the parameters...), | ||
// see the comment above. | ||
|
||
1 | ||
}); | ||
|
||
unupcasted_cost += own_entries.sum::<usize>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you uplift this comment and just use count
😅
This comment has been minimized.
This comment has been minimized.
2bef9e9
to
af4631a
Compare
@compiler-errors I've simplified the code, added some more docs, renamed some variables to make sense and finally added a test. I think this should be ready |
@bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (7b0eac4): comparison URL. Overall result: ❌✅ regressions and improvements - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 648.428s -> 648.095s (-0.05%) |
I'm pretty sure the perf changes are noise 😅 |
Is this meant to display sizes for traits that are never used with |
@kornelski yes, this is expected. theoretically it'd be possible to filter out private & not used with |
This is a bit hacky/buggy, but I'm not entirely sure how to fix it, so I want to ask reviewers for help...
To try this, use either of those:
cargo clean && RUSTFLAGS="-Zprint-vtable-sizes" cargo +toolchain b
cargo clean && cargo rustc +toolchain -Zprint-vtable-sizes
rustc +toolchain -Zprint-vtable-sizes ./file.rs