]> Cypherpunks repositories - gostls13.git/commit
runtime: pass key/value to map accessors by reference, not by value.
authorKeith Randall <khr@golang.org>
Mon, 2 Dec 2013 21:05:04 +0000 (13:05 -0800)
committerKeith Randall <khr@golang.org>
Mon, 2 Dec 2013 21:05:04 +0000 (13:05 -0800)
commit3278dc158e34779eb46cd1b5a73c1d0c18602184
tree08c1e7f3d31872ccd79e40e5d1a811af80a30677
parentde0fd9aceeeaccee8c1851c22eb8bc1b2ad913c7
runtime: pass key/value to map accessors by reference, not by value.

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
15 files changed:
src/cmd/gc/builtin.c
src/cmd/gc/fmt.c
src/cmd/gc/go.h
src/cmd/gc/range.c
src/cmd/gc/reflect.c
src/cmd/gc/runtime.go
src/cmd/gc/walk.c
src/pkg/reflect/type.go
src/pkg/reflect/value.go
src/pkg/runtime/hashmap.c
src/pkg/runtime/hashmap_fast.c
src/pkg/runtime/mapspeed_test.go
src/pkg/runtime/runtime.h
src/pkg/runtime/type.h
src/pkg/runtime/typekind.h