From 203f669ca87f9efa657e1a5e5554b1183334a5d7 Mon Sep 17 00:00:00 2001 From: Florian Lehner Date: Thu, 13 Oct 2022 01:37:26 +0200 Subject: [PATCH] preallocate memory (#2201) **What this PR does / why we need it:** Preallocate memory instead of enforcing an incremental growth. This will result in less work for the garbage collector. --- controllers/admin/viewers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/admin/viewers.go b/controllers/admin/viewers.go index e2f48b1c1..ed542a31a 100644 --- a/controllers/admin/viewers.go +++ b/controllers/admin/viewers.go @@ -37,7 +37,7 @@ func GetViewersOverTime(w http.ResponseWriter, r *http.Request) { // GetActiveViewers returns currently connected clients. func GetActiveViewers(w http.ResponseWriter, r *http.Request) { c := core.GetActiveViewers() - viewers := []models.Viewer{} + viewers := make([]models.Viewer, 0, len(c)) for _, v := range c { viewers = append(viewers, *v) }