From 0867505aa3ce879c7c9256a6e15f03e3cb6f6b8f Mon Sep 17 00:00:00 2001 From: "Jim.Idle" Date: Sun, 21 Aug 2022 12:20:13 +0800 Subject: [PATCH] feat: Reduce initial memory allocations for collections - Many small collections are created at runtime, the default allocation for maps, even though small, still requires memory. Specifying a very small initial allocation prevents unnecesary allocations and has no measurable effect on performance. A small incremental change. Signed-off-by: Jim.Idle --- runtime/Go/antlr/jcollect.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/Go/antlr/jcollect.go b/runtime/Go/antlr/jcollect.go index d7660cd915..ae49239a3f 100644 --- a/runtime/Go/antlr/jcollect.go +++ b/runtime/Go/antlr/jcollect.go @@ -38,7 +38,7 @@ func NewJStore[T any, C Comparator[T]](comparator Comparator[T]) *JStore[T, C] { } s := &JStore[T, C]{ - store: make(map[int][]T), + store: make(map[int][]T, 1), comparator: comparator, } return s @@ -138,7 +138,7 @@ type JMap[K, V any, C Comparator[K]] struct { func NewJMap[K, V any, C Comparator[K]](comparator Comparator[K]) *JMap[K, V, C] { return &JMap[K, V, C]{ - store: make(map[int][]*entry[K, V]), + store: make(map[int][]*entry[K, V], 1), comparator: comparator, } }