Closed
Conversation
Five targeted changes to reduce lock contention on the hot read path and eliminate the prefetch scheduling stall: - segmentRange.current → atomic.Int64: GetCurrentIndex() is now lock-free; called on every downloadManager iteration, this removes an RLock/RUnlock from the tightest inner loop. - UsenetReader.totalBytesRead → atomic.Int64: eliminates a sync.Mutex lock/unlock pair inside the innermost Read() byte-copy loop, the single highest-frequency lock acquisition in the codebase. - UsenetReader.nextToDownload → atomic.Int64: removes mutex from GetBufferedOffset() and simplifies downloadManager state tracking. - Replace 50ms polling timer with segmentConsumed channel: when Read() advances past a segment via rg.Next(), it sends a non-blocking signal on a buffered channel. downloadManager wakes immediately rather than waiting up to 50ms, reducing stall latency at segment boundaries (especially visible at high bitrates / fast connections). A 1s fallback timer guards against missed signals. - sync.Pool for download buffers: reuses *bytes.Buffer across segment downloads to reduce GC allocation pressure when 30+ segments are in-flight concurrently. - FUSE MaxReadAhead default: 128KB → 4MB. Usenet segments are ~750KB decoded; a 4MB kernel readahead window allows the kernel to pipeline multiple full-segment reads without stalling on round-trips, keeping the prefetch queue saturated. https://claude.ai/code/session_01Mj9fGMBVMwWXLTurDTT3Qk
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.
Five targeted changes to reduce lock contention on the hot read path
and eliminate the prefetch scheduling stall:
segmentRange.current → atomic.Int64: GetCurrentIndex() is now
lock-free; called on every downloadManager iteration, this removes
an RLock/RUnlock from the tightest inner loop.
UsenetReader.totalBytesRead → atomic.Int64: eliminates a
sync.Mutex lock/unlock pair inside the innermost Read() byte-copy
loop, the single highest-frequency lock acquisition in the codebase.
UsenetReader.nextToDownload → atomic.Int64: removes mutex from
GetBufferedOffset() and simplifies downloadManager state tracking.
Replace 50ms polling timer with segmentConsumed channel: when
Read() advances past a segment via rg.Next(), it sends a non-blocking
signal on a buffered channel. downloadManager wakes immediately
rather than waiting up to 50ms, reducing stall latency at segment
boundaries (especially visible at high bitrates / fast connections).
A 1s fallback timer guards against missed signals.
sync.Pool for download buffers: reuses *bytes.Buffer across
segment downloads to reduce GC allocation pressure when 30+
segments are in-flight concurrently.
FUSE MaxReadAhead default: 128KB → 4MB. Usenet segments are
~750KB decoded; a 4MB kernel readahead window allows the kernel to
pipeline multiple full-segment reads without stalling on round-trips,
keeping the prefetch queue saturated.