@@ -68,10 +68,21 @@ pub struct TypeSizeInfo {
68
68
69
69
pub struct VTableSizeInfo {
70
70
pub trait_name : String ,
71
- pub size_words_without_upcasting : usize ,
72
- pub size_words_with_upcasting : usize ,
73
- pub difference_words : usize ,
74
- pub difference_percent : f64 ,
71
+
72
+ /// Number of entries in a vtable with the current algorithm
73
+ /// (i.e. with upcasting).
74
+ pub entries : usize ,
75
+
76
+ /// Number of entries in a vtable, as-if we did not have trait upcasting.
77
+ pub entries_ignoring_upcasting : usize ,
78
+
79
+ /// Number of entries in a vtable needed solely for upcasting
80
+ /// (i.e. `entries - entries_ignoring_upcasting`).
81
+ pub entries_for_upcasting : usize ,
82
+
83
+ /// Cost of having upcasting in % relative to the number of entries without
84
+ /// upcasting (i.e. `entries_for_upcasting / entries_ignoring_upcasting * 100%`).
85
+ pub upcasting_cost_percent : f64 ,
75
86
}
76
87
77
88
#[ derive( Default ) ]
@@ -216,25 +227,26 @@ impl CodeStats {
216
227
}
217
228
218
229
pub fn print_vtable_sizes ( & self , crate_name : & str ) {
219
- let mut rr = std:: mem:: take ( & mut * self . vtable_sizes . lock ( ) ) . into_iter ( ) . collect :: < Vec < _ > > ( ) ;
220
-
221
- rr. sort_by ( |( _, stats_a) , ( _, stats_b) | {
222
- stats_b. difference_percent . total_cmp ( & stats_a. difference_percent )
230
+ let mut infos = std:: mem:: take ( & mut * self . vtable_sizes . lock ( ) )
231
+ . into_iter ( )
232
+ . map ( |( _did, stats) | stats)
233
+ . collect :: < Vec < _ > > ( ) ;
234
+
235
+ // Sort by the cost % in reverse order (from biggest to smallest)
236
+ infos. sort_by ( |a, b| {
237
+ a. upcasting_cost_percent . total_cmp ( & b. upcasting_cost_percent ) . reverse ( )
223
238
} ) ;
224
239
225
- for (
226
- _,
227
- VTableSizeInfo {
228
- trait_name,
229
- size_words_without_upcasting,
230
- size_words_with_upcasting,
231
- difference_words,
232
- difference_percent,
233
- } ,
234
- ) in rr
240
+ for VTableSizeInfo {
241
+ trait_name,
242
+ entries,
243
+ entries_ignoring_upcasting,
244
+ entries_for_upcasting,
245
+ upcasting_cost_percent,
246
+ } in infos
235
247
{
236
248
println ! (
237
- r#"print-vtable-sizes {{ "crate_name": "{crate_name}", "trait_name": "{trait_name}", "size_unupcastable_words ": "{size_words_without_upcasting }", "size_upcastable_words ": "{size_words_with_upcasting }", diff : "{difference_words }", diff_p : "{difference_percent }" }}"#
249
+ r#"print-vtable-sizes {{ "crate_name": "{crate_name}", "trait_name": "{trait_name}", "entries ": "{entries }", "entries_ignoring_upcasting ": "{entries_ignoring_upcasting }", "entries_for_upcasting" : "{entries_for_upcasting }", "upcasting_cost_percent" : "{upcasting_cost_percent }" }}"#
238
250
) ;
239
251
}
240
252
}
0 commit comments