@@ -536,9 +536,11 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
536536
537537 fn encode_crate_root ( & mut self ) -> LazyValue < CrateRoot > {
538538 let tcx = self . tcx ;
539- let mut i = self . position ( ) ;
539+ let mut i = 0 ;
540+ let preamble_bytes = self . position ( ) - i;
540541
541542 // Encode the crate deps
543+ i = self . position ( ) ;
542544 let crate_deps = self . encode_crate_deps ( ) ;
543545 let dylib_dependency_formats = self . encode_dylib_dependency_formats ( ) ;
544546 let dep_bytes = self . position ( ) - i;
@@ -564,7 +566,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
564566 let native_libraries = self . encode_native_libraries ( ) ;
565567 let native_lib_bytes = self . position ( ) - i;
566568
569+ i = self . position ( ) ;
567570 let foreign_modules = self . encode_foreign_modules ( ) ;
571+ let foreign_modules_bytes = self . position ( ) - i;
568572
569573 // Encode DefPathTable
570574 i = self . position ( ) ;
@@ -584,6 +588,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
584588 i = self . position ( ) ;
585589 let incoherent_impls = self . encode_incoherent_impls ( ) ;
586590 let incoherent_impls_bytes = self . position ( ) - i;
591+
587592 // Encode MIR.
588593 i = self . position ( ) ;
589594 self . encode_mir ( ) ;
@@ -596,6 +601,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
596601 let item_bytes = self . position ( ) - i;
597602
598603 // Encode the allocation index
604+ i = self . position ( ) ;
599605 let interpret_alloc_index = {
600606 let mut interpret_alloc_index = Vec :: new ( ) ;
601607 let mut n = 0 ;
@@ -618,6 +624,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
618624 }
619625 self . lazy_array ( interpret_alloc_index)
620626 } ;
627+ let interpret_alloc_index_bytes = self . position ( ) - i;
621628
622629 // Encode the proc macro data. This affects 'tables',
623630 // so we need to do this before we encode the tables
@@ -662,9 +669,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
662669 let source_map = self . encode_source_map ( ) ;
663670 let source_map_bytes = self . position ( ) - i;
664671
672+ i = self . position ( ) ;
665673 let attrs = tcx. hir ( ) . krate_attrs ( ) ;
666674 let has_default_lib_allocator = tcx. sess . contains_name ( & attrs, sym:: default_lib_allocator) ;
667-
668675 let root = self . lazy ( CrateRoot {
669676 name : tcx. crate_name ( LOCAL_CRATE ) ,
670677 extra_filename : tcx. sess . opts . cg . extra_filename . clone ( ) ,
@@ -707,9 +714,34 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
707714 expn_hashes,
708715 def_path_hash_map,
709716 } ) ;
717+ let final_bytes = self . position ( ) - i;
710718
711719 let total_bytes = self . position ( ) ;
712720
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+
713745 if tcx. sess . meta_stats ( ) {
714746 let mut zero_bytes = 0 ;
715747 for e in self . opaque . data . iter ( ) {
@@ -718,27 +750,41 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
718750 }
719751 }
720752
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 ! ( "" ) ;
742788 }
743789
744790 root
0 commit comments