Skip to content

Comments

optimize: lock-free Usenet FUSE pipeline#313

Closed
javi11 wants to merge 1 commit intomainfrom
claude/optimize-fuse-usenet-1NY2U
Closed

optimize: lock-free Usenet FUSE pipeline#313
javi11 wants to merge 1 commit intomainfrom
claude/optimize-fuse-usenet-1NY2U

Conversation

@javi11
Copy link
Owner

@javi11 javi11 commented Feb 21, 2026

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.

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
@javi11 javi11 closed this Feb 21, 2026
@javi11 javi11 deleted the claude/optimize-fuse-usenet-1NY2U branch February 21, 2026 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants