Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove common wsutil.Reader allocations #189

Merged
merged 1 commit into from
Oct 30, 2023

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
9 checks passed
@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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants