From 2f1a384bcb557b3903ada88bb96c5267aec29ea0 Mon Sep 17 00:00:00 2001 From: Derek Collison Date: Tue, 3 Oct 2023 14:39:00 -0700 Subject: [PATCH] Holding onto the compressor and not recycling the interbal byte slice was causing havoc with GC. This needs to be improved but this at least should allow the GC to cleanup more effectively. Signed-off-by: Derek Collison --- server/websocket.go | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/server/websocket.go b/server/websocket.go index 1afa3084..ff8dc1ea 100644 --- a/server/websocket.go +++ b/server/websocket.go @@ -115,7 +115,6 @@ type websocket struct { nocompfrag bool // No fragment for compressed frames maskread bool maskwrite bool - compressor *flate.Writer cookieJwt string clientIP string } @@ -1295,15 +1294,8 @@ func (c *client) wsCollapsePtoNB() (net.Buffers, int64) { if mfs > 0 && c.ws.nocompfrag { mfs = 0 } - buf := &bytes.Buffer{} - - cp := c.ws.compressor - if cp == nil { - c.ws.compressor, _ = flate.NewWriter(buf, flate.BestSpeed) - cp = c.ws.compressor - } else { - cp.Reset(buf) - } + buf := bytes.NewBuffer(nbPoolGet(usz)) + cp, _ := flate.NewWriter(buf, flate.BestSpeed) var csz int for _, b := range nb { cp.Write(b) @@ -1352,6 +1344,7 @@ func (c *client) wsCollapsePtoNB() (net.Buffers, int64) { } csz = len(h) + ol } + nbPoolPut(b) // No longer needed as we copied from above. // Add to pb the compressed data size (including headers), but // remove the original uncompressed data size that was added // during the queueing.