From ee1157c14ad5a182e1b1e03aaa5a5aef67b0a682 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Wed, 22 Mar 2023 17:11:24 +0000 Subject: [PATCH] labels: shrink stack arrays in Builder.Range Go spends some time initializing all the elements of these arrays to zero, so reduce the size from 1024 to 128. This is still much bigger than we ever expect for a set of labels. (If someone does have more than 128 labels it will still work, but via heap allocation.) Signed-off-by: Bryan Boreham --- model/labels/labels.go | 4 ++-- model/labels/labels_string.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/model/labels/labels.go b/model/labels/labels.go index 6de001c3c..8fc401564 100644 --- a/model/labels/labels.go +++ b/model/labels/labels.go @@ -547,8 +547,8 @@ func (b *Builder) Get(n string) string { // Range calls f on each label in the Builder. func (b *Builder) Range(f func(l Label)) { // Stack-based arrays to avoid heap allocation in most cases. - var addStack [1024]Label - var delStack [1024]string + var addStack [128]Label + var delStack [128]string // Take a copy of add and del, so they are unaffected by calls to Set() or Del(). origAdd, origDel := append(addStack[:0], b.add...), append(delStack[:0], b.del...) b.base.Range(func(l Label) { diff --git a/model/labels/labels_string.go b/model/labels/labels_string.go index 98db29d25..560b643db 100644 --- a/model/labels/labels_string.go +++ b/model/labels/labels_string.go @@ -601,8 +601,8 @@ func (b *Builder) Get(n string) string { // Range calls f on each label in the Builder. func (b *Builder) Range(f func(l Label)) { // Stack-based arrays to avoid heap allocation in most cases. - var addStack [1024]Label - var delStack [1024]string + var addStack [128]Label + var delStack [128]string // Take a copy of add and del, so they are unaffected by calls to Set() or Del(). origAdd, origDel := append(addStack[:0], b.add...), append(delStack[:0], b.del...) b.base.Range(func(l Label) {