• Keith Randall's avatar
    runtime: pass key/value to map accessors by reference, not by value. · 3278dc15
    Keith Randall authored
    This change is part of the plan to get rid of all vararg C calls
    which are a pain for getting exact stack scanning.
    
    We allocate a chunk of zero memory to return a pointer to when a
    map access doesn't find the key.  This is simpler than returning nil
    and fixing things up in the caller.  Linker magic allocates a single
    zero memory area that is shared by all (non-reflect-generated) map
    types.
    
    Passing things by reference gets rid of some copies, so it speeds
    up code with big keys/values.
    
    benchmark             old ns/op    new ns/op    delta
    BenchmarkBigKeyMap           34           31   -8.48%
    BenchmarkBigValMap           37           30  -18.62%
    BenchmarkSmallKeyMap         26           23  -11.28%
    
    R=golang-dev, dvyukov, khr, rsc
    CC=golang-dev
    https://golang.org/cl/14794043
    3278dc15
runtime.go 5.39 KB