@@ -733,7 +733,7 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on
733733 compilation : & mut Compilation ,
734734 ) -> Result < FxIndexMap < ChunkGroupUkey , Vec < ModuleIdentifier > > > {
735735 let mut input_entrypoints_and_modules: FxIndexMap < ChunkGroupUkey , Vec < ModuleIdentifier > > =
736- FxIndexMap :: default ( ) ;
736+ FxIndexMap :: with_capacity_and_hasher ( compilation . entries . len ( ) , Default :: default ( ) ) ;
737737
738738 let entries = compilation. entries . keys ( ) . cloned ( ) . collect :: < Vec < _ > > ( ) ;
739739
@@ -742,12 +742,16 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on
742742 all_modules
743743 . par_iter ( )
744744 . map ( |m| {
745- (
746- * m,
747- mg. get_outgoing_connections ( m)
748- . map ( |con| * con. module_identifier ( ) )
749- . collect :: < Vec < _ > > ( ) ,
750- )
745+ let mut outgoing = mg
746+ . module_graph_module_by_identifier ( m)
747+ . map ( |mgm| Vec :: with_capacity ( mgm. outgoing_connections ( ) . len ( ) ) )
748+ . unwrap_or_default ( ) ;
749+
750+ for con in mg. get_outgoing_connections ( m) {
751+ outgoing. push ( * con. module_identifier ( ) ) ;
752+ }
753+
754+ ( * m, outgoing)
751755 } )
752756 . collect :: < IdentifierMap < _ > > ( )
753757 } ;
@@ -756,12 +760,23 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on
756760 . iter ( )
757761 . map ( |name| self . prepare_entry_input ( name, compilation) )
758762 . collect :: < Result < Vec < _ > > > ( ) ?;
763+ let initial_depth_capacity = all_modules
764+ . len ( )
765+ . checked_div ( entries. len ( ) )
766+ . unwrap_or_default ( ) ;
759767
760768 let assign_depths_maps = assign_tasks
761769 . par_iter ( )
762770 . map ( |( _, modules) | {
763- let mut assign_depths_map = IdentifierMap :: default ( ) ;
764- assign_depths ( & mut assign_depths_map, modules. iter ( ) , & outgoings) ;
771+ let initial_depth_capacity = initial_depth_capacity. max ( modules. len ( ) ) ;
772+ let mut assign_depths_map =
773+ IdentifierMap :: with_capacity_and_hasher ( initial_depth_capacity, Default :: default ( ) ) ;
774+ assign_depths (
775+ & mut assign_depths_map,
776+ modules. iter ( ) ,
777+ & outgoings,
778+ initial_depth_capacity,
779+ ) ;
765780 assign_depths_map
766781 } )
767782 . collect :: < Vec < _ > > ( ) ;
0 commit comments