From 01b5233167d3f3a8eebe74ab50918424a0d7ca4d Mon Sep 17 00:00:00 2001 From: Aykhan Shahsuvarov Date: Mon, 10 Aug 2026 00:01:16 +0400 Subject: [PATCH 1/2] perf: replace status code string map with an indexed table --- internal/sarin/worker.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/sarin/worker.go b/internal/sarin/worker.go index ba97b2f..fb0648f 100644 --- a/internal/sarin/worker.go +++ b/internal/sarin/worker.go @@ -12,19 +12,19 @@ import ( const dryRunResponseKey = "dry-run" // statusCodeStrings contains pre-computed string representations for HTTP status codes 100-599. -var statusCodeStrings = func() map[int]string { - m := make(map[int]string, 500) - for i := 100; i < 600; i++ { - m[i] = strconv.Itoa(i) +var statusCodeStrings = func() [500]string { + var codes [500]string + for i := range codes { + codes[i] = strconv.Itoa(i + 100) } - return m + return codes }() // statusCodeToString returns a string representation of the HTTP status code. -// Uses a pre-computed map for codes 100-599, falls back to strconv.Itoa for others. +// Uses a pre-computed table for codes 100-599, falls back to strconv.Itoa for others. func statusCodeToString(code int) string { - if s, ok := statusCodeStrings[code]; ok { - return s + if i := code - 100; i >= 0 && i < len(statusCodeStrings) { + return statusCodeStrings[i] } return strconv.Itoa(code) } From e83e9346a3081531899ec3b2838b308e9f36a409 Mon Sep 17 00:00:00 2001 From: Aykhan Shahsuvarov Date: Mon, 10 Aug 2026 00:10:27 +0400 Subject: [PATCH 2/2] perf: drop redundant resp.Reset in worker loops fasthttp resets the response at the top of every HostClient.Do, so resetting it in the worker loop only repeats that work once per request. --- internal/sarin/worker.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/internal/sarin/worker.go b/internal/sarin/worker.go index fb0648f..6cb9531 100644 --- a/internal/sarin/worker.go +++ b/internal/sarin/worker.go @@ -94,7 +94,6 @@ func (s sarin) workerStatsWithDynamic( ) { for range jobs { req.Reset() - resp.Reset() if err := requestGenerator(req); err != nil { s.responses.Add(err.Error(), 0) @@ -138,8 +137,6 @@ func (s sarin) workerStatsWithStatic( } for range jobs { - resp.Reset() - startTime := time.Now() err := hostClientGenerator().DoTimeout(req, resp, s.timeout) respDuration := time.Since(startTime) @@ -165,7 +162,6 @@ func (s sarin) workerNoStatsWithDynamic( ) { for range jobs { req.Reset() - resp.Reset() if err := requestGenerator(req); err != nil { sendLog(runtimeLogLevelError, err.Error()) counter.Add(1) @@ -201,7 +197,6 @@ func (s sarin) workerNoStatsWithStatic( } for range jobs { - resp.Reset() startTime := time.Now() err := hostClientGenerator().DoTimeout(req, resp, s.timeout) if err == nil {