Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor optimization by avoiding fmt.Sprintf on hot path #962

Merged
merged 1 commit into from
Nov 11, 2024

Conversation

pior
Copy link
Contributor

@pior pior commented Nov 10, 2024

Context

While fmt.Sprintf is handy, and usually fast enough for most use-cases, we should probably avoid using it for string concatenation on the hot path.

Micro-benchmark:

BenchmarkBase/sprintf-8         	19425255	        61.85 ns/op	      32 B/op	       2 allocs/op
BenchmarkBase/concat-8          	84949484	        14.20 ns/op	       0 B/op	       0 allocs/op

Changes

  • Replace fmt.Sprintf with string concatenation when building redis key names/prefixes

Copy link

codecov bot commented Nov 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 66.31%. Comparing base (4f00f52) to head (2d6d6f4).
Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #962      +/-   ##
==========================================
- Coverage   67.13%   66.31%   -0.83%     
==========================================
  Files          29       29              
  Lines        4300     5729    +1429     
==========================================
+ Hits         2887     3799     +912     
- Misses       1135     1651     +516     
- Partials      278      279       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kamikazechaser kamikazechaser merged commit 1a7c61a into hibiken:master Nov 11, 2024
9 of 10 checks passed
@pior pior deleted the str-concat branch November 12, 2024 09:25
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