• Kirill Smelkov's avatar
    X zodb/cache: Also free OCE entries on GC · 521d3ae5
    Kirill Smelkov authored
    Until now we were only GC'ing RCE entries, but OCE entries (top-level
    cache entry for an OID) were never GC'ed thus allowing cache size to
    grow infinitely.
    
    Even though the average N(allocations) stays the same this change lowers
    pressure on amount of memory allocated and thus helping avoid some GC
    speeds things up (see attachment).
    
    Notes:
    
    1. Hit*/size=0 increase is probably due to Cache.entryMap going to
       empty/1-element back and forth constantly. size/0 is not going to
       happen in practice and so this wat we can accept regression here.
    
       ( still NoHit*/size=0 works faster ).
    
    2. HitProc/size=* "regression should be within noise"
    
    name                        old time/op    new time/op    delta
    NoopStorage-4                 56.6ns ± 1%    56.2ns ± 0%       ~     (p=0.079 n=5+5)
    CacheStartup-4                1.24µs ± 6%    1.28µs ± 9%       ~     (p=0.595 n=5+5)
    CacheNoHit/size=0-4           1.44µs ± 4%    0.93µs ± 2%    -35.26%  (p=0.008 n=5+5)
    CacheNoHit/size=16-4          1.43µs ± 5%    0.92µs ± 1%    -35.19%  (p=0.008 n=5+5)
    CacheNoHit/size=128-4         1.45µs ± 3%    0.94µs ± 1%    -35.03%  (p=0.008 n=5+5)
    CacheNoHit/size=512-4         1.44µs ± 4%    0.97µs ± 2%    -32.64%  (p=0.008 n=5+5)
    CacheNoHit/size=4096-4        1.45µs ± 2%    1.07µs ± 0%    -25.85%  (p=0.008 n=5+5)
    CacheHit/size=0-4              131ns ± 2%     276ns ±22%   +110.99%  (p=0.008 n=5+5)
    CacheHit/size=16-4             122ns ± 1%     121ns ± 1%       ~     (p=0.079 n=5+5)
    CacheHit/size=128-4            126ns ± 2%     125ns ± 1%       ~     (p=0.563 n=5+5)
    CacheHit/size=512-4            127ns ± 1%     126ns ± 0%       ~     (p=0.095 n=5+4)
    CacheHit/size=4096-4           128ns ± 0%     128ns ± 0%       ~     (p=0.556 n=5+4)
    NoopStoragePar-4              30.6ns ± 4%    31.2ns ±10%       ~     (p=0.690 n=5+5)
    CacheStartupPar-4             1.44µs ± 5%    1.43µs ± 3%       ~     (p=0.690 n=5+5)
    CacheNoHitPar/size=0-4        1.62µs ± 4%    1.04µs ± 1%    -35.76%  (p=0.008 n=5+5)
    CacheNoHitPar/size=16-4       1.65µs ± 4%    1.05µs ± 1%    -36.39%  (p=0.008 n=5+5)
    CacheNoHitPar/size=128-4      1.64µs ± 5%    1.05µs ± 1%    -35.84%  (p=0.008 n=5+5)
    CacheNoHitPar/size=512-4      1.62µs ± 3%    1.08µs ± 1%    -33.10%  (p=0.008 n=5+5)
    CacheNoHitPar/size=4096-4     1.68µs ± 1%    1.18µs ± 0%    -29.44%  (p=0.008 n=5+5)
    CacheHitPar/size=0-4           215ns ± 0%     383ns ± 2%    +78.23%  (p=0.008 n=5+5)
    CacheHitPar/size=16-4          214ns ± 2%     214ns ± 0%       ~     (p=0.786 n=5+5)
    CacheHitPar/size=128-4         210ns ± 0%     209ns ± 0%       ~     (p=0.079 n=5+5)
    CacheHitPar/size=512-4         207ns ± 0%     206ns ± 0%     -0.48%  (p=0.008 n=5+5)
    CacheHitPar/size=4096-4        204ns ± 0%     202ns ± 0%     -0.98%  (p=0.000 n=5+4)
    NoopStorageProc-4             31.4ns ± 7%    33.7ns ± 5%       ~     (p=0.151 n=5+5)
    CacheStartupProc-4            1.13µs ± 5%    1.12µs ± 3%       ~     (p=0.690 n=5+5)
    CacheNoHitProc/size=0-4       1.12µs ± 5%    0.62µs ± 1%    -44.52%  (p=0.008 n=5+5)
    CacheNoHitProc/size=16-4      1.14µs ± 6%    0.63µs ± 1%    -45.14%  (p=0.008 n=5+5)
    CacheNoHitProc/size=128-4     1.06µs ± 5%    0.64µs ± 2%    -40.12%  (p=0.008 n=5+5)
    CacheNoHitProc/size=512-4     1.14µs ±11%    0.69µs ± 4%    -39.87%  (p=0.008 n=5+5)
    CacheNoHitProc/size=4096-4    1.14µs ± 9%    0.68µs ± 2%    -40.21%  (p=0.008 n=5+5)
    CacheHitProc/size=0-4         56.5ns ± 7%    84.6ns ±14%    +49.66%  (p=0.008 n=5+5)
    CacheHitProc/size=16-4        55.8ns ± 0%    62.0ns ± 6%    +11.03%  (p=0.008 n=5+5)
    CacheHitProc/size=128-4       56.6ns ± 0%    60.9ns ± 4%     +7.63%  (p=0.008 n=5+5)
    CacheHitProc/size=512-4       57.3ns ± 0%    64.1ns ± 7%    +11.83%  (p=0.016 n=4+5)
    CacheHitProc/size=4096-4      61.6ns ± 1%    69.7ns ± 5%    +13.29%  (p=0.008 n=5+5)
    
    name                        old alloc/op   new alloc/op   delta
    NoopStorage-4                  0.00B          0.00B            ~     (all equal)
    CacheStartup-4                  269B ± 0%      285B ± 0%     +5.95%  (p=0.008 n=5+5)
    CacheNoHit/size=0-4             225B ± 0%      153B ± 0%    -32.12%  (p=0.008 n=5+5)
    CacheNoHit/size=16-4            225B ± 0%      153B ± 0%    -32.00%  (p=0.029 n=4+4)
    CacheNoHit/size=128-4           225B ± 1%      153B ± 0%    -31.76%  (p=0.008 n=5+5)
    CacheNoHit/size=512-4           225B ± 1%      154B ± 0%    -31.50%  (p=0.008 n=5+5)
    CacheNoHit/size=4096-4          224B ± 0%      155B ± 0%    -30.80%  (p=0.008 n=5+5)
    CacheHit/size=0-4              0.00B         13.40B ±42%      +Inf%  (p=0.008 n=5+5)
    CacheHit/size=16-4             0.00B          0.00B            ~     (all equal)
    CacheHit/size=128-4            0.00B          0.00B            ~     (all equal)
    CacheHit/size=512-4            0.00B          0.00B            ~     (all equal)
    CacheHit/size=4096-4           0.00B          0.00B            ~     (all equal)
    NoopStoragePar-4               0.00B          0.00B            ~     (all equal)
    CacheStartupPar-4               267B ± 0%      282B ± 1%     +5.67%  (p=0.016 n=4+5)
    CacheNoHitPar/size=0-4          232B ± 1%      162B ± 1%    -30.11%  (p=0.008 n=5+5)
    CacheNoHitPar/size=16-4         228B ± 1%      161B ± 0%    -29.21%  (p=0.008 n=5+5)
    CacheNoHitPar/size=128-4        229B ± 1%      162B ± 0%    -29.43%  (p=0.008 n=5+5)
    CacheNoHitPar/size=512-4        228B ± 1%      162B ± 1%    -28.86%  (p=0.008 n=5+5)
    CacheNoHitPar/size=4096-4       224B ± 0%      166B ± 0%    -26.02%  (p=0.000 n=5+4)
    CacheHitPar/size=0-4           1.00B ± 0%    13.60B ± 4%  +1260.00%  (p=0.008 n=5+5)
    CacheHitPar/size=16-4          0.00B          0.00B            ~     (all equal)
    CacheHitPar/size=128-4         0.00B          0.00B            ~     (all equal)
    CacheHitPar/size=512-4         0.00B          0.00B            ~     (all equal)
    CacheHitPar/size=4096-4        0.00B          0.00B            ~     (all equal)
    NoopStorageProc-4              0.00B          0.00B            ~     (all equal)
    CacheStartupProc-4              269B ± 0%      285B ± 0%     +5.95%  (p=0.008 n=5+5)
    CacheNoHitProc/size=0-4         240B ± 0%      194B ± 0%    -19.17%  (p=0.000 n=5+4)
    CacheNoHitProc/size=16-4        240B ± 2%      194B ± 1%    -19.38%  (p=0.008 n=5+5)
    CacheNoHitProc/size=128-4       241B ± 0%      193B ± 1%    -20.00%  (p=0.016 n=4+5)
    CacheNoHitProc/size=512-4       241B ± 1%      188B ± 2%    -22.06%  (p=0.008 n=5+5)
    CacheNoHitProc/size=4096-4      240B ± 1%      179B ± 0%    -25.52%  (p=0.008 n=5+5)
    CacheHitProc/size=0-4          0.00B          3.60B ±17%      +Inf%  (p=0.008 n=5+5)
    CacheHitProc/size=16-4         0.00B          0.00B            ~     (all equal)
    CacheHitProc/size=128-4        0.00B          0.00B            ~     (all equal)
    CacheHitProc/size=512-4        0.00B          0.00B            ~     (all equal)
    CacheHitProc/size=4096-4       0.00B          0.00B            ~     (all equal)
    
    name                        old allocs/op  new allocs/op  delta
    NoopStorage-4                   0.00           0.00            ~     (all equal)
    CacheStartup-4                  5.00 ± 0%      5.00 ± 0%       ~     (all equal)
    CacheNoHit/size=0-4             3.00 ± 0%      3.00 ± 0%       ~     (all equal)
    CacheNoHit/size=16-4            3.00 ± 0%      3.00 ± 0%       ~     (all equal)
    CacheNoHit/size=128-4           3.00 ± 0%      3.00 ± 0%       ~     (all equal)
    CacheNoHit/size=512-4           3.00 ± 0%      3.00 ± 0%       ~     (all equal)
    CacheNoHit/size=4096-4          3.00 ± 0%      3.00 ± 0%       ~     (all equal)
    CacheHit/size=0-4               0.00           0.00            ~     (all equal)
    CacheHit/size=16-4              0.00           0.00            ~     (all equal)
    CacheHit/size=128-4             0.00           0.00            ~     (all equal)
    CacheHit/size=512-4             0.00           0.00            ~     (all equal)
    CacheHit/size=4096-4            0.00           0.00            ~     (all equal)
    NoopStoragePar-4                0.00           0.00            ~     (all equal)
    CacheStartupPar-4               4.00 ± 0%      4.00 ± 0%       ~     (all equal)
    CacheNoHitPar/size=0-4          3.00 ± 0%      3.00 ± 0%       ~     (all equal)
    CacheNoHitPar/size=16-4         3.00 ± 0%      3.00 ± 0%       ~     (all equal)
    CacheNoHitPar/size=128-4        3.00 ± 0%      3.00 ± 0%       ~     (all equal)
    CacheNoHitPar/size=512-4        3.00 ± 0%      3.00 ± 0%       ~     (all equal)
    CacheNoHitPar/size=4096-4       3.00 ± 0%      3.00 ± 0%       ~     (all equal)
    CacheHitPar/size=0-4            0.00           0.00            ~     (all equal)
    CacheHitPar/size=16-4           0.00           0.00            ~     (all equal)
    CacheHitPar/size=128-4          0.00           0.00            ~     (all equal)
    CacheHitPar/size=512-4          0.00           0.00            ~     (all equal)
    CacheHitPar/size=4096-4         0.00           0.00            ~     (all equal)
    NoopStorageProc-4               0.00           0.00            ~     (all equal)
    CacheStartupProc-4              5.00 ± 0%      5.00 ± 0%       ~     (all equal)
    CacheNoHitProc/size=0-4         3.00 ± 0%      3.00 ± 0%       ~     (all equal)
    CacheNoHitProc/size=16-4        3.00 ± 0%      3.00 ± 0%       ~     (all equal)
    CacheNoHitProc/size=128-4       3.00 ± 0%      3.00 ± 0%       ~     (all equal)
    CacheNoHitProc/size=512-4       3.00 ± 0%      3.00 ± 0%       ~     (all equal)
    CacheNoHitProc/size=4096-4      3.00 ± 0%      3.00 ± 0%       ~     (all equal)
    CacheHitProc/size=0-4           0.00           0.00            ~     (all equal)
    CacheHitProc/size=16-4          0.00           0.00            ~     (all equal)
    CacheHitProc/size=128-4         0.00           0.00            ~     (all equal)
    CacheHitProc/size=512-4         0.00           0.00            ~     (all equal)
    CacheHitProc/size=4096-4        0.00           0.00            ~     (all equal)
    521d3ae5
cache.go 18.4 KB