Skip to content

Commit

Permalink
cluster: perf optimize tracer's version feature gate
Browse files Browse the repository at this point in the history
`version.IsActive` unmarshals a protobuf (and this isn't trivial to
fix), so let the tracer cache a positive result. This means that in
the common case, IsActive is not on the hot path any more.

Release justification: low-risk performance improvement
Release note: None
  • Loading branch information
tbg committed Feb 25, 2021
1 parent c8f9f61 commit bec47d3
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pkg/settings/cluster/cluster_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,19 @@ func MakeClusterSettings() *Settings {
sv.Init(s.Version)

s.Tracer = tracing.NewTracer()
isActive := int32(0) // atomic
s.Tracer.TracingVerbosityIndependentSemanticsIsActive = func() bool {
return s.Version.IsActive(context.Background(),
clusterversion.TracingVerbosityIndependentSemantics)
// IsActive is mildly expensive for the hot path this function
// is in, so cache a return value of true.
if atomic.LoadInt32(&isActive) != 0 {
return true
}
if s.Version.IsActive(context.Background(),
clusterversion.TracingVerbosityIndependentSemantics) {
atomic.StoreInt32(&isActive, 1)
return true
}
return false
}
s.Tracer.Configure(sv)

Expand Down

0 comments on commit bec47d3

Please sign in to comment.