From bec47d32fd2fbb99cda1764bd66194547389c2e1 Mon Sep 17 00:00:00 2001 From: Tobias Grieger Date: Thu, 25 Feb 2021 11:30:37 +0100 Subject: [PATCH] cluster: perf optimize tracer's version feature gate `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 --- pkg/settings/cluster/cluster_settings.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/settings/cluster/cluster_settings.go b/pkg/settings/cluster/cluster_settings.go index 7d6c461ba62a..aa0cd7e7a238 100644 --- a/pkg/settings/cluster/cluster_settings.go +++ b/pkg/settings/cluster/cluster_settings.go @@ -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)