Skip to content

Commit af5c951

Browse files
valyalaianlancetaylor
authored andcommittedApr 18, 2017
sync: improve Pool performance
Rewrite indexLocal to achieve higher performance. Performance results on linux/amd64: name old time/op new time/op delta Pool-4 19.1ns ± 2% 10.1ns ± 1% -47.15% (p=0.000 n=10+8) PoolOverflow-4 3.11µs ± 1% 2.10µs ± 2% -32.66% (p=0.000 n=10+10) Performance results on linux/386: name old time/op new time/op delta Pool-4 20.0ns ± 2% 13.1ns ± 1% -34.59% (p=0.000 n=10+9) PoolOverflow-4 3.51µs ± 1% 2.49µs ± 0% -28.99% (p=0.000 n=10+8) Change-Id: I7d57a2d4cd47ec43d09ca1267bde2e3f05a9faa9 Reviewed-on: https://go-review.googlesource.com/40913 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
1 parent c239fbb commit af5c951

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed
 

‎src/sync/pool.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ func init() {
241241
}
242242

243243
func indexLocal(l unsafe.Pointer, i int) *poolLocal {
244-
return &(*[1000000]poolLocal)(l)[i]
244+
lp := unsafe.Pointer(uintptr(l) + uintptr(i)*unsafe.Sizeof(poolLocal{}))
245+
return (*poolLocal)(lp)
245246
}
246247

247248
// Implemented in runtime.

0 commit comments

Comments
 (0)
Please sign in to comment.