]> Cypherpunks.ru repositories - gostls13.git/commit
reflect: optimize for maps with string keys
authorJoe Tsai <joetsai@digital-static.net>
Fri, 27 Aug 2021 02:13:22 +0000 (19:13 -0700)
committerJoe Tsai <joetsai@digital-static.net>
Sat, 11 Sep 2021 05:05:56 +0000 (05:05 +0000)
commit23832ba2e2fb396cda1dacf3e8afcb38ec36dcba
treef96434832d4ef0d5b124ac333d250766a415d522
parenta50225a0dc1e83449a76b80b2fbed77af516483c
reflect: optimize for maps with string keys

Over 80% of all Go map types use a string as the key.
The Go runtime already has a specialized implementation for such maps
in runtime/map_faststr.go. However, the Go reflection implementation
has not historically made use of that implementation.

This CL plumbs the appropriate logic to be accessible from Go reflection
so that it can benefit as well.

    name                            old time/op    new time/op    delta
    Map/StringKeys/MapIndex-4       4.65us ± 5%    2.95us ± 3%  -36.50%  (p=0.016 n=4+5)
    Map/StringKeys/SetMapIndex-4    7.47us ± 5%    5.27us ± 2%  -29.40%  (p=0.008 n=5+5)
    Map/Uint64Keys/MapIndex-4       3.79us ± 3%    3.75us ± 2%     ~     (p=0.548 n=5+5)
    Map/Uint64Keys/SetMapIndex-4    6.13us ± 3%    6.09us ± 1%     ~     (p=0.746 n=5+5)

Change-Id: I5495d48948d8caf2d004a03ae1820ab5f8729670
Reviewed-on: https://go-review.googlesource.com/c/go/+/345486
Trust: Joe Tsai <joetsai@digital-static.net>
Run-TryBot: Joe Tsai <joetsai@digital-static.net>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/reflect/all_test.go
src/reflect/value.go
src/runtime/map.go