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

Prevent copying on each read in websocket #150

Open
sergiu128 opened this issue Dec 3, 2024 · 0 comments
Open

Prevent copying on each read in websocket #150

sergiu128 opened this issue Dec 3, 2024 · 0 comments

Comments

@sergiu128
Copy link
Collaborator

sergiu128 commented Dec 3, 2024

We currently have AsyncNextMessage(b []byte, ...) where the message's payload is read into b. The issue is that the payload is copied from the websocket's internal buffer into b. We can remove this copy. Two cases:

  • if the message is made up of a single frame, then just return the payload of that frame in the callback of the new function
  • if the message is made up of multiple frames, then return the payloads of all those frames in a callback

So the function signature would look something like this:

AsyncNextMessageDirect(func(error, MessageType, b ...[]byte))

Then callers have the option to either read the fragments one by one or reassemble them. We can help with the reassembly by introducing a new construct: FrameAssembler. I think this one just needs to concatenate all []bytes. Callers will be expected to not hold onto the []bytes after the callback returns.

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

No branches or pull requests

1 participant