]> Cypherpunks.ru repositories - gostls13.git/commit
sync/atomic: reduce inlining cost for atomic types methods
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Fri, 9 Sep 2022 13:38:18 +0000 (20:38 +0700)
committerGopher Robot <gobot@golang.org>
Fri, 9 Sep 2022 18:21:40 +0000 (18:21 +0000)
commit9dd9174fa55b8078892f8a6d1863715f313d6880
tree887f4abf55e23378403d543b050e507f0e0fbeb7
parente2f602003bb81dc3385c488a6635e2504d0abfbd
sync/atomic: reduce inlining cost for atomic types methods

The "&x.v" cost us 2 inline cost budget, causing extra inline cost for
the caller. By taking the fact that "v" is laid out in memory as the
first field of all atomic types, we can accessing it without addressing.

Discovering why attempting to convert sync.RWMutex.readerCount to atomic
type. RWMutex.RUnlock have the inline cost 75, with extra 7 inline cost
from Int32.Add causing it not inlinable anymore.

With this change, Int32.Add only has 5 inline cost budget, RWMutex can
use it while still be inlinable.

Change-Id: Iabe1d1bf53389b0b8b5f56b4611231b732fd9df5
Reviewed-on: https://go-review.googlesource.com/c/go/+/429766
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
src/sync/atomic/type.go