summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-02-24 21:34:07 +0200
committerPaul Buetow <paul@buetow.org>2026-02-24 21:34:07 +0200
commitfc8b25518a006c4103c7d0cba56626ce725d3462 (patch)
tree38dea9cdb2aa28a2d23fe8011fb39726d4e9e353
parent66850d3350faae19a495a6668035239b6df7c0a8 (diff)
flamegraph: pool FNV hasher for frame colors
-rw-r--r--internal/flamegraph/svgwriter.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/internal/flamegraph/svgwriter.go b/internal/flamegraph/svgwriter.go
index 5e3a3fc..4457fba 100644
--- a/internal/flamegraph/svgwriter.go
+++ b/internal/flamegraph/svgwriter.go
@@ -3,9 +3,11 @@ package flamegraph
import (
"bufio"
"fmt"
+ "hash"
"hash/fnv"
"io"
"strings"
+ "sync"
)
var svgEscaper = strings.NewReplacer(
@@ -16,6 +18,12 @@ var svgEscaper = strings.NewReplacer(
"'", "&apos;",
)
+var fnv32aPool = sync.Pool{
+ New: func() any {
+ return fnv.New32a()
+ },
+}
+
type SVGConfig struct {
Title string
Width int
@@ -135,9 +143,11 @@ func writeFrame(bw *bufio.Writer, name, title, fill string, x, y, w, h float64,
}
func frameColor(name string) string {
- hasher := fnv.New32a()
- _, _ = hasher.Write([]byte(name))
+ hasher := fnv32aPool.Get().(hash.Hash32)
+ hasher.Reset()
+ _, _ = io.WriteString(hasher, name)
h := hasher.Sum32()
+ fnv32aPool.Put(hasher)
r := 200 + int(h%35)
g := 80 + int((h>>8)%120)
b := 40 + int((h>>16)%90)