Skip to content

network: reuse the noise record layer's read buffers - #52

Draft
AminMGMT wants to merge 1 commit into
mainfrom
claude/project-thread-g53mbx
Draft

AminMGMT wants to merge 1 commit into
mainfrom
claude/project-thread-g53mbx

Conversation

@AminMGMT

Copy link
Copy Markdown
Owner

Requested by Amin · project thread

Before: TestTheRecordLayerDoesNotAllocatePerRecord failed on main for every target, with 3 allocations per record on amd64 and 5 on 386 against a limit of 2.

After: it passes, with 2 on amd64 and 1 on 386.

The write side was already fixed to reuse its frame buffer. The read side still allocated a new frame buffer for every record, a header array that escaped through io.ReadFull, and a separate plaintext buffer from Decrypt(nil, …).

How: noiseConn now keeps an inBuf. readNoiseFrameInto reads the header and body into it and only grows it when a record doesn't fit, and Read decrypts in place (Decrypt(frame[:0], nil, frame)). This is safe because readBuf always points into inBuf, and the next record is only read once readBuf is empty. The handshake still goes through readNoiseFrame, which is now a thin wrapper.

Found during a v1.8.4 release check. All 7 release targets (linux 386, amd64, arm64, armv5/6/7, s390x) build and pass go vet before and after this change.

🤖 Generated with Claude Code

https://claude.ai/code/session_01W2VziS7icb6hVwbTgrJF3W


Generated by Claude Code

TestTheRecordLayerDoesNotAllocatePerRecord failed on every target (3
allocs per record on amd64, 5 on 386, limit 2): the read side allocated
a fresh frame buffer, a header array that escaped through io.ReadFull,
and a separate plaintext buffer for every record. Read now reads each
record into a buffer the connection keeps and decrypts it in place.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W2VziS7icb6hVwbTgrJF3W
@AminMGMT AminMGMT self-assigned this Sep 27, 2026
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