7

Start improving monomorphization items stats by lqd · Pull Request #105481 · rus...

 1 year ago
source link: https://github.com/rust-lang/rust/pull/105481
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Member

@lqd lqd commented Dec 9, 2022

edited

As described in this zulip discussion, some stats about monomorphization collection would be interesting to have, in a different form than -Zprint-mono-items: to have some visibility into the cost of the mono items, we'd like to know how many are instantiated and what is their estimated size.

That can be a proxy to analyze sources of slow compile times, although in the future, we'd also like to add more realistic stats from the actual backend's lowering.

This PR adds a new -Z dump-mono-stats flag which will output some stats in a {crate_name}.mono-items.md file (the flag optionally takes an output directory parameter, for easier use within a workspace than printing to stdout).

For example,

fn compute<T>(collection: Vec<T>) -> usize {
    collection.len() + 19 - 0 * 9 - 18 - 1 * 1 // random code to increase the function's size
}

fn main() {
    dbg!(compute(vec![0u8, 1, 2]));
    dbg!(compute(vec![0u64, 1, 2]));
    dbg!(compute(vec!["0", "1", "2", "3"]));
}

will output a file with this markdown table (abridged for readability), for a debug build:

Item Instantiation count Estimated Cost Per Instantiation Total Estimated Cost
alloc::alloc::box_free 3 122 366
std::alloc::Global::alloc_impl 1 284 284
alloc::raw_vec::RawVec::<T, A>::current_memory 3 82 246
std::ptr::align_offset 1 222 222
std::slice::hack::into_vec 3 67 201
<std::vec::Vec<T, A> as std::ops::Drop>::drop 3 66 198
std::ptr::mut_ptr::<impl *mut T>::is_null 4 47 188
main 1 163 163
std::ptr::NonNull::::new_unchecked 4 37 148
...
Click for full output

Since we discussed it together, r? @wesleywiser.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK