@@ -254,8 +254,10 @@ impl<'a, K: DepKind + Decodable<MemDecoder<'a>>> Decodable<MemDecoder<'a>>
254
254
// end of the array. This padding ensure it doesn't.
255
255
edge_list_data. extend ( & [ 0u8 ; DEP_NODE_PAD ] ) ;
256
256
257
- let mut index: Vec < _ > =
258
- iter:: repeat ( FxHashMap :: default ( ) ) . take ( K :: MAX as usize + 1 ) . collect ( ) ;
257
+ // Read the number of each dep kind and use it to create an hash map with a suitable size.
258
+ let mut index: Vec < _ > = ( 0 ..( K :: MAX as usize + 1 ) )
259
+ . map ( |_| FxHashMap :: with_capacity_and_hasher ( d. read_u32 ( ) as usize , Default :: default ( ) ) )
260
+ . collect ( ) ;
259
261
260
262
for ( idx, node) in nodes. iter_enumerated ( ) {
261
263
index[ node. kind . to_u16 ( ) as usize ] . insert ( node. hash , idx) ;
@@ -426,6 +428,9 @@ struct EncoderState<K: DepKind> {
426
428
total_node_count : usize ,
427
429
total_edge_count : usize ,
428
430
stats : Option < FxHashMap < K , Stat < K > > > ,
431
+
432
+ /// Stores the number of times we've encoded each dep kind.
433
+ kind_stats : Vec < u32 > ,
429
434
}
430
435
431
436
impl < K : DepKind > EncoderState < K > {
@@ -435,6 +440,7 @@ impl<K: DepKind> EncoderState<K> {
435
440
total_edge_count : 0 ,
436
441
total_node_count : 0 ,
437
442
stats : record_stats. then ( FxHashMap :: default) ,
443
+ kind_stats : iter:: repeat ( 0 ) . take ( K :: MAX as usize + 1 ) . collect ( ) ,
438
444
}
439
445
}
440
446
@@ -445,6 +451,7 @@ impl<K: DepKind> EncoderState<K> {
445
451
) -> DepNodeIndex {
446
452
let index = DepNodeIndex :: new ( self . total_node_count ) ;
447
453
self . total_node_count += 1 ;
454
+ self . kind_stats [ node. node . kind . to_u16 ( ) as usize ] += 1 ;
448
455
449
456
let edge_count = node. edges . len ( ) ;
450
457
self . total_edge_count += edge_count;
@@ -470,11 +477,16 @@ impl<K: DepKind> EncoderState<K> {
470
477
}
471
478
472
479
fn finish ( self , profiler : & SelfProfilerRef ) -> FileEncodeResult {
473
- let Self { mut encoder, total_node_count, total_edge_count, stats : _ } = self ;
480
+ let Self { mut encoder, total_node_count, total_edge_count, stats : _, kind_stats } = self ;
474
481
475
482
let node_count = total_node_count. try_into ( ) . unwrap ( ) ;
476
483
let edge_count = total_edge_count. try_into ( ) . unwrap ( ) ;
477
484
485
+ // Encode the number of each dep kind encountered
486
+ for count in kind_stats. iter ( ) {
487
+ count. encode ( & mut encoder) ;
488
+ }
489
+
478
490
debug ! ( ?node_count, ?edge_count) ;
479
491
debug ! ( "position: {:?}" , encoder. position( ) ) ;
480
492
IntEncodedWithFixedSize ( node_count) . encode ( & mut encoder) ;
0 commit comments