I was profiling the memory allocation for our kite library (github.com/koding/kite). It uses the sockjs server extensively, and I saw that for every single request we would compile the regexp object, even if it's the same. We know add a hot cache, evaluated lazily for a prefix. The results can be seen below and it dramatically changes the speed and memory allocation of the handler. Change between the old and new can be seen below: ``` benchmark old ns/op new ns/op delta BenchmarkHandler_ParseSessionID 19985 4465 -77.66% benchmark old allocs new allocs delta BenchmarkHandler_ParseSessionID 61 2 -96.72% benchmark old bytes new bytes delta BenchmarkHandler_ParseSessionID 6560 96 -98.54% ```
…rios by introducing sleep periods to let other wheels spin.
With large messages on XHR-streaming and XHR-poll (possibly others) the stateHTTPReceiverClosed state may be set on httpReceiver, which causes future calls to sendBulk to be a no-op until another receiver attaches. This is usually not a problem because a goroutine in session.attachReceiver calls detachReceiver soon after, and detach causes the session's recv field to be nulled out. However, if msgs are sent between the time when stateHTTPReceiverClosed is called and detachReceiver occurs, then those messages will be silently ignored.