-
Notifications
You must be signed in to change notification settings - Fork 312
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
Can not do Zero alloc reads and writes. #354
Comments
Use my internal tool, I find that all the allocs is from Conn.Writer/io.Copy in serverside code。 |
Then I have tried websocket.NetConn on both side, then I got:
It is also not zero alloc . |
zero alloc read/write message modify over github.com/nhooyr/websocket
This change will make "Concurrent writes" invalid.... |
So I comfirmed that it can not zero-alloced write message right now. It can zero-alloced read message. |
Will test. |
@nhooyr can you please clarify if its correct whats stated in the README or not? |
To the best of my knowledge it was correct when I wrote it but it's been a few years now so I need to retest everything I'm claiming in the README. |
Ah, yes the README should be clarified to indicate that only Reads are zero alloc though as you noticed. |
I added a script to make testing this stuff much easier. See
The other allocations are red herrings from pprof itself. The first one is the one you noticed as well. |
The reason it does an alloc anyway btw is to prevent closed writers from being used improperly. If I remove the allocation, then a writer obtained, written to and closed, will be open again when someone else is writing as there will only ever be one Writer pointer. |
But I think that's ok, quite unlikely for writers to be used after closed in most code I think as you have to call Close and so you have to be clear of its the lifetime. |
Fixed in dev! |
I wrote some tests, here is my code:
The text was updated successfully, but these errors were encountered: