aboutsummaryrefslogtreecommitdiff
path: root/pkg/api/api0/serverlist.go
diff options
context:
space:
mode:
authorpg9182 <96569817+pg9182@users.noreply.github.com>2022-10-23 11:55:44 -0400
committerpg9182 <96569817+pg9182@users.noreply.github.com>2022-10-23 11:55:44 -0400
commit7c2d07e66a2c5d4630aa2c435c37cd2a667dff7d (patch)
tree7fa2f957c5574d1ea6fb7333e71e24bf0db133c3 /pkg/api/api0/serverlist.go
parentfeda74ade1e09541b30a00d51f2950681e70cd7c (diff)
downloadAtlas-7c2d07e66a2c5d4630aa2c435c37cd2a667dff7d.tar.gz
Atlas-7c2d07e66a2c5d4630aa2c435c37cd2a667dff7d.zip
pkg/api/api0/serverlist: Use sync.Pool for gzip writers
Diffstat (limited to 'pkg/api/api0/serverlist.go')
-rw-r--r--pkg/api/api0/serverlist.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/pkg/api/api0/serverlist.go b/pkg/api/api0/serverlist.go
index 53f7b95..021af65 100644
--- a/pkg/api/api0/serverlist.go
+++ b/pkg/api/api0/serverlist.go
@@ -45,6 +45,7 @@ type ServerList struct {
csBytes atomic.Pointer[[]byte] // contents of buffer must not be modified; only swapped
// /client/servers gzipped json
+ csgzPool sync.Pool // gzip writer pool
csgzUpdate atomic.Pointer[*byte] // pointer to the first byte of the last known json (works because it must be swapped, not modified)
csgzUpdatePf bool // ensures only one update runs at a time
csgzUpdateCv *sync.Cond // allows other goroutines to wait for that update to complete
@@ -351,7 +352,14 @@ func (s *ServerList) csGetJSONGzip() ([]byte, bool) {
}
var b bytes.Buffer
- zw := gzip.NewWriter(&b)
+ var zw *gzip.Writer
+ if o := s.csgzPool.Get(); o == nil {
+ zw = gzip.NewWriter(&b)
+ } else {
+ zw = o.(*gzip.Writer)
+ zw.Reset(&b)
+ }
+ defer s.csgzPool.Put(zw)
if _, err := zw.Write(buf); err != nil {
s.csgzBytes.Store(nil)
s.csgzUpdate.Store(&cur)