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

x/net/websocket: Frame masking code is very inefficient [includes fix] #5269

Closed
gopherbot opened this issue Apr 11, 2013 · 4 comments
Closed

x/net/websocket: Frame masking code is very inefficient [includes fix] #5269

gopherbot opened this issue Apr 11, 2013 · 4 comments
Milestone

Comments

@gopherbot
Copy link

@gopherbot gopherbot commented Apr 11, 2013

by Jens.Alfke:

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).

Attachments:

  1. websocket.patch (473 bytes)
@remyoudompheng
Copy link
Contributor

@remyoudompheng remyoudompheng commented Apr 11, 2013

Comment 1:

Please follow the instructions at http://golang.org/doc/contribute.html to propose a
patch.
@robpike
Copy link
Contributor

@robpike robpike commented Apr 11, 2013

Comment 2:

Please send a CL or, since this is so small, say it's OK for us to just make this
trivial change.

Labels changed: added priority-later, removed priority-triage.

Status changed to Accepted.

@gopherbot
Copy link
Author

@gopherbot gopherbot commented Apr 17, 2013

Comment 3 by Jens.Alfke:

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.)
@minux
Copy link
Member

@minux minux commented Apr 17, 2013

Comment 4:

This issue was closed by revision golang/net@94458b3.

Status changed to Fixed.

@mikioh mikioh added repo-net and removed repo-net labels Dec 23, 2014
@mikioh 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 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
@mikioh mikioh modified the milestone: Unreleased Jul 30, 2015
@golang golang locked and limited conversation to collaborators Aug 5, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.