Skip to content

Conversation

@klauspost
Copy link
Contributor

image

  • ws.ReadHeader allocates a 12 byte temporary buffer to read the header into. Since io.ReadFull is used, it escapes to the heap.

  • wsutil.NewCipherReader is allocated on each call to NextFrame.

Since the NextFrame shouldn't have concurrent calls, both of these should be possible to have internally.

I am forced to copy "readHeader" from ws, since there is not way to eliminate the alloc otherwise as far as I can tell.

![image](https://github.com/gobwas/ws/assets/5663952/b7f5a544-f6f0-44cf-b38c-e89fd3de0bd4)

* `ws.ReadHeader` allocates a 12 byte temporary buffer to read the header into. Since `io.ReadFull` is used, it escapes to the heap.

* `wsutil.NewCipherReader` is used for many calls.

Since the `NextFrame` shouldn't have concurrent calls, both of these should be possible to have internally.

I am forced to copy "readHeader" from `ws`, since there is not way to eliminate the alloc otherwise as far as I can tell.
@cristaloleg cristaloleg merged commit 516805a into gobwas:master Oct 30, 2023
@cristaloleg
Copy link
Collaborator

Thanks! I will finish #171 tomorrow and will release a new version.

@klauspost klauspost deleted the remove-wsutil-reader-allocs branch October 30, 2023 16:18
klauspost added a commit to klauspost/minio that referenced this pull request Nov 1, 2023
Removes some minor allocations and cleans up benchmarks as well as adds typed roundtrip benchmarks.

Websocket library updated to include gobwas/ws#189
@klauspost klauspost mentioned this pull request Nov 1, 2023
1 task
klauspost added a commit to klauspost/minio that referenced this pull request Nov 1, 2023
Removes some minor allocations and cleans up benchmarks as well as adds typed roundtrip benchmarks.

Websocket library updated to include gobwas/ws#189
harshavardhana pushed a commit to minio/minio that referenced this pull request Nov 1, 2023
Removes some minor allocations and cleans up benchmarks as well as adds typed roundtrip benchmarks.

Websocket library updated to include gobwas/ws#189
@cristaloleg
Copy link
Collaborator

Sorry for the delay, released as v1.3.1 https://github.com/gobwas/ws/releases/tag/v1.3.1

klauspost added a commit to klauspost/minio that referenced this pull request Nov 16, 2023
Removes some minor allocations and cleans up benchmarks as well as adds typed roundtrip benchmarks.

Websocket library updated to include gobwas/ws#189
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants