Skip to content

Commit

Permalink
stop: elide trace.Region when no exec trace active
Browse files Browse the repository at this point in the history
`StartRegion` does one allocation, might as well save it
in the common case of execution tracing not being active.

Epic: none
Release note: None
  • Loading branch information
tbg committed Sep 12, 2024
1 parent 0afe71c commit 3bf34dc
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pkg/util/stop/stopper.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,18 @@ func (s *Stopper) RunTask(ctx context.Context, taskName string, f func(context.C
return nil
}

func (s *Stopper) startRegion(ctx context.Context, taskName string) *trace.Region {
type region interface {
End()
}

type noopRegion struct{}

func (n noopRegion) End() {}

func (s *Stopper) startRegion(ctx context.Context, taskName string) region {
if !trace.IsEnabled() {
return noopRegion{}
}
return trace.StartRegion(ctx, taskName)
}

Expand Down

0 comments on commit 3bf34dc

Please sign in to comment.