Skip to content

Reduce cache listener command allocations - #204

Merged
enteriaza merged 1 commit into
masterfrom
159-perf-allocation-cache-listener-copies-each-command-line-and-message-id-out-of-the-pending-buffer
Oct 19, 2026
Merged

enteriaza merged 1 commit into
masterfrom
159-perf-allocation-cache-listener-copies-each-command-line-and-message-id-out-of-the-pending-buffer

Conversation

@enteriaza

Copy link
Copy Markdown
Collaborator

Summary

Reduces per-command allocations in NntpCacheListenerSession by parsing commands directly from the pending buffer and reusing per-session response buffers.

Closes #159.

Changes

  • Zero-copy command parsing: Return a view of _pending instead of allocating a new array for every command line.
  • Zero-copy Message-ID parsing: Return a slice of the existing command memory rather than allocating a separate argument array.
  • Reusable ARTICLE response buffer: Format 220 status lines into session-owned storage, avoiding a new array per ARTICLE command.
  • Reusable DATE response buffer: Format 111 responses into a fixed-size, session-owned buffer.
  • Preserved buffer lifetime: Keep command bytes valid until the handler completes, including awaited response writes, before consuming the command from _pending.
  • Documented memory ownership: Clarify that CommandReadKind.Command references the pending buffer and must not outlive its valid contents.

The per-read CancellationTokenSource allocation in StreamCacheListenerTransport is unchanged.

Testing and validation

  • Focused cache-listener tests: 105 passed
  • BackFillerService tests: 1,233 passed, 0 failed (--no-build)
  • Release x64 solution build: passed, 0 warnings and 0 errors
  • Solution formatting verification: passed

Notes

  • Protocol response formats and command behavior remain unchanged.
  • No measured gen-0 allocation-rate comparison has been performed.
  • CodeQL and Linux CI have not been run.

Fixes #159

Parse commands and Message-IDs directly from the pending buffer, and reuse per-session ARTICLE and DATE response buffers. Preserve command-buffer lifetime through handler completion and document the non-owning command memory contract.
@enteriaza enteriaza self-assigned this Oct 19, 2026
@enteriaza enteriaza added the enhancement New feature or request label Oct 19, 2026
@enteriaza
enteriaza merged commit 3280161 into master Oct 19, 2026
7 checks passed
@enteriaza
enteriaza deleted the 159-perf-allocation-cache-listener-copies-each-command-line-and-message-id-out-of-the-pending-buffer branch October 19, 2026 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Perf: Allocation] Cache listener copies each command line and Message-ID out of the pending buffer

1 participant