• Brad Fitzpatrick's avatar
    runtime: allocate maps' first bucket table lazily · 5b3ff61b
    Brad Fitzpatrick authored
    Motivated by garbage profiling in HTTP benchmarks. This
    changes means new empty maps are just one small allocation
    (the HMap) instead the HMap + the relatively larger h->buckets
    allocation. This helps maps which remain empty throughout
    their life.
    
    benchmark               old ns/op    new ns/op    delta
    BenchmarkNewEmptyMap          196          107  -45.41%
    
    benchmark              old allocs   new allocs    delta
    BenchmarkNewEmptyMap            2            1  -50.00%
    
    benchmark               old bytes    new bytes    delta
    BenchmarkNewEmptyMap          195           50  -74.36%
    
    R=khr, golang-dev, r
    CC=golang-dev
    https://golang.org/cl/7722046
    5b3ff61b
map_test.go 5.5 KB