siso: create span name once and reuse for every call

semaphore creates span name every call, but
it would be better to create span name once and resuse it in every call
to reduce memory allocation / GC pressure.

Change-Id: Idd273f5e45b601c102d2e5dbcff66f0369376afc
Reviewed-on: https://chromium-review.googlesource.com/c/infra/infra/+/5107538
Reviewed-by: Junji Watanabe <jwata@google.com>
Auto-Submit: Fumitoshi Ukai <ukai@google.com>
Commit-Queue: Junji Watanabe <jwata@google.com>
Cr-Commit-Position: refs/heads/main@{#61797}
diff --git a/go/src/infra/build/siso/sync/semaphore/semaphore.go b/go/src/infra/build/siso/sync/semaphore/semaphore.go
index b1c0820..88aa389 100644
--- a/go/src/infra/build/siso/sync/semaphore/semaphore.go
+++ b/go/src/infra/build/siso/sync/semaphore/semaphore.go
@@ -27,6 +27,9 @@
 	name string
 	ch   chan int
 
+	waitSpanName string
+	servSpanName string
+
 	waits atomic.Int64
 	reqs  atomic.Int64
 }
@@ -49,8 +52,10 @@
 		ch <- i + 1 // tid
 	}
 	s := &Semaphore{
-		name: name,
-		ch:   ch,
+		name:         name,
+		ch:           ch,
+		waitSpanName: fmt.Sprintf("wait:%s", name),
+		servSpanName: fmt.Sprintf("serv:%s", name),
 	}
 	mu.Lock()
 	semaphores[name] = s
@@ -62,14 +67,14 @@
 // It returns a context for acquired semaphore and func to release it.
 // TODO(b/267576561): add Cloud Trace integration and add tid as an attribute of a Span.
 func (s *Semaphore) WaitAcquire(ctx context.Context) (context.Context, func(error), error) {
-	_, span := trace.NewSpan(ctx, fmt.Sprintf("wait:%s", s.name))
+	_, span := trace.NewSpan(ctx, s.waitSpanName)
 	s.waits.Add(1)
 	defer span.Close(nil)
 	defer s.waits.Add(-1)
 	select {
 	case tid := <-s.ch:
 		s.reqs.Add(1)
-		ctx, span := trace.NewSpan(ctx, fmt.Sprintf("serv:%s", s.name))
+		ctx, span := trace.NewSpan(ctx, s.servSpanName)
 		span.SetAttr("tid", tid)
 		return ctx, func(err error) {
 			st, ok := status.FromError(err)
@@ -93,7 +98,7 @@
 	select {
 	case tid := <-s.ch:
 		s.reqs.Add(1)
-		ctx, span := trace.NewSpan(ctx, fmt.Sprintf("serv:%s", s.name))
+		ctx, span := trace.NewSpan(ctx, s.servSpanName)
 		span.SetAttr("tid", tid)
 		return ctx, func(err error) {
 			st, ok := status.FromError(err)