Skip to content
Snippets Groups Projects
Commit 266814f5 authored by David Fifield's avatar David Fifield
Browse files

Manually unlock the mutex in ClientMap.SendQueue.

Rather than use defer. It is only a tiny amount faster, but this
function is frequently called.

Before:
	$ go test -bench=BenchmarkSendQueue -benchtime=2s
	BenchmarkSendQueue-4    15901834               151 ns/op
After:
	$ go test -bench=BenchmarkSendQueue -benchtime=2s
	BenchmarkSendQueue-4    15859948               147 ns/op

tpo/anti-censorship/pluggable-transports/snowflake#40177
parent 3185487a
No related branches found
No related tags found
No related merge requests found
......@@ -57,8 +57,9 @@ func NewClientMap(timeout time.Duration) *ClientMap {
// necessary.
func (m *ClientMap) SendQueue(addr net.Addr) chan []byte {
m.lock.Lock()
defer m.lock.Unlock()
return m.inner.SendQueue(addr, time.Now())
queue := m.inner.SendQueue(addr, time.Now())
m.lock.Unlock()
return queue
}
// clientMapInner is the inner type of ClientMap, implementing heap.Interface.
......
package turbotunnel
import (
"testing"
"time"
)
// Benchmark the ClientMap.SendQueue function. This is mainly measuring the cost
// of the mutex operations around the call to clientMapInner.SendQueue.
func BenchmarkSendQueue(b *testing.B) {
m := NewClientMap(1 * time.Hour)
id := NewClientID()
m.SendQueue(id) // populate the entry for id
b.ResetTimer()
for i := 0; i < b.N; i++ {
m.SendQueue(id)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment