[txndefer] Remove theoretically unnecessary locking.
R=tandrii@chromium.org
Change-Id: I31c6f4c3ea241942fb992d9d1d3a3e4f3322543c
Reviewed-on: https://chromium-review.googlesource.com/c/infra/luci/gae/+/2321570
Reviewed-by: Andrii Shyshkalov <tandrii@google.com>
Commit-Queue: Vadim Shtayura <vadimsh@chromium.org>
diff --git a/filter/txndefer/filter.go b/filter/txndefer/filter.go
index 0c998ea..c00434a 100644
--- a/filter/txndefer/filter.go
+++ b/filter/txndefer/filter.go
@@ -74,8 +74,12 @@
}
func (s *txnState) execCBs() {
- s.m.Lock()
- defer s.m.Unlock()
+ // Note: execCBs happens after RunInTransaction has finished. If it spawned
+ // any goroutines, they must have been finished already too (calling Defer
+ // from a goroutine that outlives a transaction is rightfully a race). Thus
+ // all writes to `s.cbs` are finished already and we also passed some
+ // synchronization barrier that waited for the goroutines to join. It's fine
+ // to avoid locking s.m in this case saving 200ns on hot code path.
if len(s.cbs) != 0 {
ctx := ds.WithoutTransaction(s.ctx)
for i := len(s.cbs) - 1; i >= 0; i-- {