@@ -536,9 +536,11 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
536
536
537
537
fn encode_crate_root ( & mut self ) -> LazyValue < CrateRoot > {
538
538
let tcx = self . tcx ;
539
- let mut i = self . position ( ) ;
539
+ let mut i = 0 ;
540
+ let preamble_bytes = self . position ( ) - i;
540
541
541
542
// Encode the crate deps
543
+ i = self . position ( ) ;
542
544
let crate_deps = self . encode_crate_deps ( ) ;
543
545
let dylib_dependency_formats = self . encode_dylib_dependency_formats ( ) ;
544
546
let dep_bytes = self . position ( ) - i;
@@ -564,7 +566,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
564
566
let native_libraries = self . encode_native_libraries ( ) ;
565
567
let native_lib_bytes = self . position ( ) - i;
566
568
569
+ i = self . position ( ) ;
567
570
let foreign_modules = self . encode_foreign_modules ( ) ;
571
+ let foreign_modules_bytes = self . position ( ) - i;
568
572
569
573
// Encode DefPathTable
570
574
i = self . position ( ) ;
@@ -584,6 +588,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
584
588
i = self . position ( ) ;
585
589
let incoherent_impls = self . encode_incoherent_impls ( ) ;
586
590
let incoherent_impls_bytes = self . position ( ) - i;
591
+
587
592
// Encode MIR.
588
593
i = self . position ( ) ;
589
594
self . encode_mir ( ) ;
@@ -596,6 +601,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
596
601
let item_bytes = self . position ( ) - i;
597
602
598
603
// Encode the allocation index
604
+ i = self . position ( ) ;
599
605
let interpret_alloc_index = {
600
606
let mut interpret_alloc_index = Vec :: new ( ) ;
601
607
let mut n = 0 ;
@@ -618,6 +624,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
618
624
}
619
625
self . lazy_array ( interpret_alloc_index)
620
626
} ;
627
+ let interpret_alloc_index_bytes = self . position ( ) - i;
621
628
622
629
// Encode the proc macro data. This affects 'tables',
623
630
// so we need to do this before we encode the tables
@@ -662,9 +669,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
662
669
let source_map = self . encode_source_map ( ) ;
663
670
let source_map_bytes = self . position ( ) - i;
664
671
672
+ i = self . position ( ) ;
665
673
let attrs = tcx. hir ( ) . krate_attrs ( ) ;
666
674
let has_default_lib_allocator = tcx. sess . contains_name ( & attrs, sym:: default_lib_allocator) ;
667
-
668
675
let root = self . lazy ( CrateRoot {
669
676
name : tcx. crate_name ( LOCAL_CRATE ) ,
670
677
extra_filename : tcx. sess . opts . cg . extra_filename . clone ( ) ,
@@ -707,9 +714,34 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
707
714
expn_hashes,
708
715
def_path_hash_map,
709
716
} ) ;
717
+ let final_bytes = self . position ( ) - i;
710
718
711
719
let total_bytes = self . position ( ) ;
712
720
721
+ let computed_total_bytes = preamble_bytes
722
+ + dep_bytes
723
+ + lib_feature_bytes
724
+ + lang_item_bytes
725
+ + diagnostic_item_bytes
726
+ + native_lib_bytes
727
+ + foreign_modules_bytes
728
+ + def_path_table_bytes
729
+ + traits_bytes
730
+ + impls_bytes
731
+ + incoherent_impls_bytes
732
+ + mir_bytes
733
+ + item_bytes
734
+ + interpret_alloc_index_bytes
735
+ + proc_macro_data_bytes
736
+ + tables_bytes
737
+ + debugger_visualizers_bytes
738
+ + exported_symbols_bytes
739
+ + hygiene_bytes
740
+ + def_path_hash_map_bytes
741
+ + source_map_bytes
742
+ + final_bytes;
743
+ assert_eq ! ( total_bytes, computed_total_bytes) ;
744
+
713
745
if tcx. sess . meta_stats ( ) {
714
746
let mut zero_bytes = 0 ;
715
747
for e in self . opaque . data . iter ( ) {
@@ -718,27 +750,41 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
718
750
}
719
751
}
720
752
721
- eprintln ! ( "metadata stats:" ) ;
722
- eprintln ! ( " dep bytes: {}" , dep_bytes) ;
723
- eprintln ! ( " lib feature bytes: {}" , lib_feature_bytes) ;
724
- eprintln ! ( " lang item bytes: {}" , lang_item_bytes) ;
725
- eprintln ! ( " diagnostic item bytes: {}" , diagnostic_item_bytes) ;
726
- eprintln ! ( " native bytes: {}" , native_lib_bytes) ;
727
- eprintln ! ( " debugger visualizers bytes: {}" , debugger_visualizers_bytes) ;
728
- eprintln ! ( " source_map bytes: {}" , source_map_bytes) ;
729
- eprintln ! ( " traits bytes: {}" , traits_bytes) ;
730
- eprintln ! ( " impls bytes: {}" , impls_bytes) ;
731
- eprintln ! ( " incoherent_impls bytes: {}" , incoherent_impls_bytes) ;
732
- eprintln ! ( " exp. symbols bytes: {}" , exported_symbols_bytes) ;
733
- eprintln ! ( " def-path table bytes: {}" , def_path_table_bytes) ;
734
- eprintln ! ( " def-path hashes bytes: {}" , def_path_hash_map_bytes) ;
735
- eprintln ! ( " proc-macro-data-bytes: {}" , proc_macro_data_bytes) ;
736
- eprintln ! ( " mir bytes: {}" , mir_bytes) ;
737
- eprintln ! ( " item bytes: {}" , item_bytes) ;
738
- eprintln ! ( " table bytes: {}" , tables_bytes) ;
739
- eprintln ! ( " hygiene bytes: {}" , hygiene_bytes) ;
740
- eprintln ! ( " zero bytes: {}" , zero_bytes) ;
741
- eprintln ! ( " total bytes: {}" , total_bytes) ;
753
+ let perc = |bytes| ( bytes * 100 ) as f64 / total_bytes as f64 ;
754
+ let p = |label, bytes| {
755
+ eprintln ! ( "{:>21}: {:>8} bytes ({:4.1}%)" , label, bytes, perc( bytes) ) ;
756
+ } ;
757
+
758
+ eprintln ! ( "" ) ;
759
+ eprintln ! (
760
+ "{} metadata bytes, of which {} bytes ({:.1}%) are zero" ,
761
+ total_bytes,
762
+ zero_bytes,
763
+ perc( zero_bytes)
764
+ ) ;
765
+ p ( "preamble" , preamble_bytes) ;
766
+ p ( "dep" , dep_bytes) ;
767
+ p ( "lib feature" , lib_feature_bytes) ;
768
+ p ( "lang item" , lang_item_bytes) ;
769
+ p ( "diagnostic item" , diagnostic_item_bytes) ;
770
+ p ( "native lib" , native_lib_bytes) ;
771
+ p ( "foreign modules" , foreign_modules_bytes) ;
772
+ p ( "def-path table" , def_path_table_bytes) ;
773
+ p ( "traits" , traits_bytes) ;
774
+ p ( "impls" , impls_bytes) ;
775
+ p ( "incoherent_impls" , incoherent_impls_bytes) ;
776
+ p ( "mir" , mir_bytes) ;
777
+ p ( "item" , item_bytes) ;
778
+ p ( "interpret_alloc_index" , interpret_alloc_index_bytes) ;
779
+ p ( "proc-macro-data" , proc_macro_data_bytes) ;
780
+ p ( "tables" , tables_bytes) ;
781
+ p ( "debugger visualizers" , debugger_visualizers_bytes) ;
782
+ p ( "exported symbols" , exported_symbols_bytes) ;
783
+ p ( "hygiene" , hygiene_bytes) ;
784
+ p ( "def-path hashes" , def_path_hash_map_bytes) ;
785
+ p ( "source_map" , source_map_bytes) ;
786
+ p ( "final" , final_bytes) ;
787
+ eprintln ! ( "" ) ;
742
788
}
743
789
744
790
root
0 commit comments