Skip to content
  • Herbert Valerio Riedel's avatar
    Use hash-consing to optimise index cache (#3897) · e0dd63cc
    Herbert Valerio Riedel authored
    Without this optimisation, `cabal info somethingnonexisting` results in
    
         960,397,120 bytes allocated in the heap
         739,652,560 bytes copied during GC
          67,757,128 bytes maximum residency (24 sample(s))
           2,234,096 bytes maximum slop
                 147 MB total memory in use (0 MB lost due to fragmentation)
    
    with this optimisation:
    
       1,000,825,744 bytes allocated in the heap
         656,112,432 bytes copied during GC
          44,476,616 bytes maximum residency (24 sample(s))
           2,302,864 bytes maximum slop
                 109 MB total memory in use (0 MB lost due to fragmentation)
    
    So the total memory in use is significantly lower. The total runtime is
    also slightly reduced, from
    
      INIT    time    0.001s  (  0.001s elapsed)
      MUT     time    0.683s  (  1.050s elapsed)
      GC      time    0.946s  (  0.946s elapsed)
      EXIT    time    0.005s  (  0.005s elapsed)
      Total   time    1.637s  (  2.002s elapsed)
    
    to
    
      INIT    time    0.001s  (  0.001s elapsed)
      MUT     time    0.664s  (  0.988s elapsed)
      GC      time    0.797s  (  0.797s elapsed)
      EXIT    time    0.004s  (  0.004s elapsed)
      Total   time    1.467s  (  1.789s elapsed)
    
    
    Note that there's currently ~80k cache entries, but only ~10k unique package names
    and ~6k unique versions. So hash-consing helps reduce the amount of heap objects 
    for both value types by one order of magnitude, which among other benefits also
    reduces GC overhead.
    e0dd63cc