-
Notifications
You must be signed in to change notification settings - Fork 18.6k
Closed
Labels
Milestone
Description
The benchmark https://play.golang.org/p/nI4LO1wu17 shows a significant slowdown when using runtime.LockOSThread.
On amd64 at current tip I see this output from go test -test.cpu=1,2,4,8 -test.bench=.:
BenchmarkUnlocked 3000000 500 ns/op
BenchmarkUnlocked-2 3000000 638 ns/op
BenchmarkUnlocked-4 2000000 749 ns/op
BenchmarkUnlocked-8 2000000 911 ns/op
BenchmarkLocked 200000 7887 ns/op
BenchmarkLocked-2 200000 8048 ns/op
BenchmarkLocked-4 200000 8235 ns/op
BenchmarkLocked-8 200000 7882 ns/op
The problem may be entirely due to the extra thread context switches required by runtime.LockOSThread. When the thread is not locked, the channel communication may be done in practice by a simple goroutine switch. When using runtime.LockOSThread a full thread context switch is required.
Still, we should make sure we have the tools to confirm that.