Repository navigation
Conversation
Member
|
Did you change your mind about releasing this to v4? :) Main is v5 |
Contributor
Author
|
My local branch got into a weird state. I'll re-apply to v4 after. |
Loop.Err is a non-blocking select on the done channel, which Go
compiles to a runtime.selectnbrecv call that cannot be inlined away.
Conn.Write and Conn.Read call it once per packet, so it is measurable
on packet-heavy workloads: it accounted for 5% of flat CPU in a profile
of an SFU fanning video to ~7k subscribers.
Add Loop.Closed, an atomic load that mirrors done and inlines into its
callers, and use it to gate the Conn.Read, Conn.Write and
Conn.WriteToPair error paths and the Loop.Run fast path. The flag is
stored after done is closed, so Closed always implies Err is non-nil
and the callers can keep reporting Err itself. Err and Done are
untouched and remain the exact context.Context implementation, both
reading only the done channel.
BenchmarkErr-10 4.65 ns/op
BenchmarkClosed-10 2.13 ns/op
goos: darwin, goarch: arm64, cpu: Apple M1 Pro
asnyatkov
force-pushed
the
perf/taskloop-err-atomic
branch
from
September 28, 2026 18:16
e728202 to
d4aba4f
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1018 +/- ##
==========================================
- Coverage 91.90% 91.88% -0.02%
==========================================
Files 46 46
Lines 5510 5511 +1
==========================================
Hits 5064 5064
- Misses 446 447 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Loop.Err is a non-blocking select on the done channel, which Go compiles to a runtime.selectnbrecv call that cannot be inlined away. Conn.Write and Conn.Read call it once per packet, so it is measurable on packet-heavy workloads: it accounted for 5% of flat CPU in a profile of an SFU fanning video to ~7k subscribers.
Add Loop.Closed, an atomic load that mirrors done and inlines into its callers, and use it to gate the Conn.Read, Conn.Write and Conn.WriteToPair error paths and the Loop.Run fast path. The flag is stored after done is closed, so Closed always implies Err is non-nil and the callers can keep reporting Err itself. Err and Done are untouched and remain the exact context.Context implementation, both reading only the done channel.
goos: darwin, goarch: arm64, cpu: Apple M1 Pro
Description
Reference issue
Fixes #...