You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The code for masking outgoing frames in hybi.go is very inefficient. It starts with an
empty byte array and uses append() to append the masked bytes one at a time. This
results in a lot of unnecessary allocations, especially with larger frames. It showed up
clearly as a hot-spot in some CPU profiling I did with a project that sends frames on
the order of 50kbytes.
It's very easy to fix this code to preallocate the array to the correct size and copy
the masked bytes into it in a tight loop. This has a pretty dramatic effect on
performance.
Attached is the fix as a tiny two-line patch based on commit adcbdfde2e2f (which was tip
a few days ago).
It's fine to make the trivial change. (I'm not set up to contribute CLs and I think it'd
be much quicker for someone already on the team to do so for me.)
mikioh
changed the title
go.net/websocket: Frame masking code is very inefficient [includes fix]
websocket: Frame masking code is very inefficient [includes fix]
Jan 4, 2015
mikioh
changed the title
websocket: Frame masking code is very inefficient [includes fix]
x/net/websocket: Frame masking code is very inefficient [includes fix]
Jul 30, 2015
by Jens.Alfke:
Attachments:
The text was updated successfully, but these errors were encountered: