Repository navigation
perf: parse WebSocket handshake headers lazily - #610
Conversation
Use iterators for header tokens and extension parameters instead of collecting split values into slices. Preserve handshake negotiation behavior.
mafredri
left a comment
There was a problem hiding this comment.
Nice cleanup. Switching handshake header parsing to iterators avoids intermediate slice allocations and skips extension parsing when CompressionDisabled is set.
A few things to address before merging:
- Per-offer heap escapes in
acceptDeflate/websocketExtension(inline onaccept.go:329-353). - Repeated
Sec-WebSocket-Protocolscans inselectSubprotocol(inline onaccept.go:267-276). - Broader test and benchmark coverage beyond delimiter-only
Acceptheaders (inline onaccept_test.go:595-631).
Minor notes (non-blocking):
verifyServerExtensionsdrops the: %+v(exts[1:]) suffix from its error string, andselectSubprotocolnow skips empty tokens even ifAcceptOptions.Subprotocolscontains"". Both are reasonable changes; worth noting briefly in the PR description / commit message instead of saying all behavior is unchanged.- The
test (1.26)goroutine-leak failure is not caused by this PR. The samepersistConnleak reproduces locally onmasterwithTestBadDials/badReq/badTLS.
🤖 Created with the help of Coder Agents.
Assert that allocations and bytes stay flat as non-empty handshake tokens grow. Store extension parameters without per-offer closures and allocate compression options only for accepted offers.
Retain only higher-ranked server preferences after a match. Check exact heap allocation counts with a fixed byte ceiling across the handshake parsing cases.
|
Looks good now, thanks for iterating on Re: storing One tiny non-blocking note for the PR description / squash commit: worth mentioning the shortened
|
Optimize WebSocket handshake header parsing with
strings.SplitSeqiterators instead of constructing slices of tokens and extension parameters.Coder Agents on behalf of @Emyrk.