summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-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(
"'", "'",
)
+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)