Skip to content

perf: replace fmt with strconv to reduce allocations#55

Merged
pkieltyka merged 1 commit intogo-chi:masterfrom
EricGusmao:reduce-allocations
Oct 8, 2025
Merged

perf: replace fmt with strconv to reduce allocations#55
pkieltyka merged 1 commit intogo-chi:masterfrom
EricGusmao:reduce-allocations

Conversation

@EricGusmao
Copy link
Copy Markdown
Contributor

This change replaces fmt.Sprintf with the more performant strconv package for basic type conversions.

The strconv functions are significantly faster and result in fewer memory allocations because they avoid the overhead of reflection that fmt uses for its flexibility.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Oct 8, 2025

Benchmark Results

goos: linux
goarch: amd64
pkg: github.com/go-chi/httprate
cpu: AMD EPYC 7763 64-Core Processor                
               │ master.txt  │            pr.txt             │
               │   sec/op    │   sec/op     vs base          │
LocalCounter-4   32.21m ± 1%   32.18m ± 2%  ~ (p=0.971 n=10)

               │  master.txt  │             pr.txt             │
               │     B/op     │     B/op      vs base          │
LocalCounter-4   2.843Mi ± 0%   2.842Mi ± 0%  ~ (p=0.631 n=10)

               │ master.txt  │            pr.txt             │
               │  allocs/op  │  allocs/op   vs base          │
LocalCounter-4   121.6k ± 0%   121.5k ± 0%  ~ (p=0.646 n=10)

@pkieltyka pkieltyka merged commit be2ba84 into go-chi:master Oct 8, 2025
2 checks passed
@EricGusmao EricGusmao deleted the reduce-allocations branch October 8, 2025 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants