-
Notifications
You must be signed in to change notification settings - Fork 18k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
runtime: buffered channels are slower than a slice and a mutex #6394
Labels
Comments
Slightly less awful on linux/arm localhost(~/go/src/pkg/fmt) % ~/go/misc/benchcmp {old,new}.txt benchmark old ns/op new ns/op delta BenchmarkSprintfEmpty 751 889 +18.38% BenchmarkSprintfString 1702 1999 +17.45% BenchmarkSprintfInt 1405 1701 +21.07% BenchmarkSprintfIntInt 1981 2234 +12.77% BenchmarkSprintfPrefixedInt 1978 2237 +13.09% BenchmarkSprintfFloat 4079 4397 +7.80% BenchmarkManyArgs 7054 7197 +2.03% BenchmarkScanInts 5443710 5773931 +6.07% BenchmarkScanRecursiveInt 7618105 8175157 +7.31% |
A buffered channel is a slice, a mutex, and extra stuff to make select work. It would be embarrassing for the slice and mutex if that combination were somehow faster than a slice+mutex alone. So "buffered channels are slower than a slice and a mutex" is working as intended. There is a possibly bigger difference in your CL, though. The slice+mutex in fmt is a stack, and you are replacing it with a queue. If there are five entries in the cache, the stack will just keep reusing one of them, while the queue will cycle through all five. You'll touch less memory using the stack, which is part of why it's there. Status changed to WorkingAsIntended. |
rod-hynes
added a commit
to rod-hynes/psiphon-tunnel-core
that referenced
this issue
Dec 29, 2014
…'default' select case which always ran. As this case was important to prevent callers to recordStat() from blocking forever, and a robust fix appeared complex, I have simply removed the processStats goro and associated channel. A buffered channel requires a mutex lock in any case [1], and the mutex-protected logic, now inline in recordStat, will execute in fractions of a microsecond. I believe that the goro/channel is not worth the extra complexity at this time. [1] golang/go#6394
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: