gossip: avoid allocation of UnresolvedAddr in getNodeIDAddressLocked#29585
gossip: avoid allocation of UnresolvedAddr in getNodeIDAddressLocked#29585craig[bot] merged 1 commit intocockroachdb:masterfrom
Conversation
petermattis
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 0 of 0 LGTMs obtained (and 1 stale)
pkg/gossip/gossip.go, line 1003 at r1 (raw file):
return nil, err } for i, locality := range nd.LocalityAddress {
Nit: we could kill both birds with one stone by removing the locality variable here and defining it as a pointer inside of the loop:
for i := range nd.LocalityAddress {
locality := &nd.LocalityAddress[i]
}
384cc2a to
9d226a4
Compare
nvb
left a comment
There was a problem hiding this comment.
bors r+
Reviewable status:
complete! 0 of 0 LGTMs obtained (and 1 stale)
pkg/gossip/gossip.go, line 1003 at r1 (raw file):
Previously, petermattis (Peter Mattis) wrote…
Nit: we could kill both birds with one stone by removing the
localityvariable here and defining it as a pointer inside of the loop:for i := range nd.LocalityAddress { locality := &nd.LocalityAddress[i] }
Good idea, done.
`getNodeIDAddressLocked` is called from `Dialer.ConnHealth` and `Dialer.DialInternalClient`. It was responsible for 1.71% of all allocations on a 3-node long running cluster that was running TPC-C 1K. Pointing into `nd.LocalityAddress` is safe because even if the `NodeDescriptor` itself is replaced in `Gossip`, the struct is never internally mutated. This is the same reason why taking the address of `nd.Address` was already safe. Release note (performance improvement): Avoid allocation when checking RPC connection health.
a-robinson
left a comment
There was a problem hiding this comment.
Are you saying that this removed allocations on a cluster that wasn't even using locality-scoped addresses?
29574: storage: update import path for Raft r=petermattis a=tschottdorf upstream moved from github.com/etcd to go.etcd.io/etcd. We're going to have to pick up an update soon to fix #28918, so it's easier to switch now. We're not picking up any new commits except for the renames. Release note: None 29585: gossip: avoid allocation of UnresolvedAddr in getNodeIDAddressLocked r=nvanbenschoten a=nvanbenschoten `getNodeIDAddressLocked` is called from `Dialer.ConnHealth` and `Dialer.DialInternalClient`. It was responsible for **1.71%** of all allocations (`alloc_objects`) on a 3-node long-running cluster that was running TPC-C 1K. Pointing into `nd.LocalityAddress` is safe because even if the `NodeDescriptor` itself is replaced in `Gossip`, the struct is never internally mutated. This is the same reason why taking the address of `nd.Address` was already safe. Release note (performance improvement): Avoid allocation when checking RPC connection health. Co-authored-by: Tobias Schottdorf <tobias.schottdorf@gmail.com> Co-authored-by: Nathan VanBenschoten <nvanbenschoten@gmail.com>
Build succeeded |
@a-robinson and I took this conversation offline and figured out what was going on. It turns out that even when a loop is never entered, if its loop variable escapes and is moved to the heap then it will result in an allocation. We can see this in the following assembly (with some added comments for ease of reading). We also noticed that this |
getNodeIDAddressLockedis called fromDialer.ConnHealthandDialer.DialInternalClient. It was responsible for 1.71% of allallocations (
alloc_objects) on a 3-node long-running cluster thatwas running TPC-C 1K.
Pointing into
nd.LocalityAddressis safe because even if theNodeDescriptoritself is replaced in
Gossip, the struct is never internally mutated. This isthe same reason why taking the address of
nd.Addresswas already safe.Release note (performance improvement): Avoid allocation when
checking RPC connection health.