[PR #962] [MERGED] Minor optimization by avoiding fmt.Sprintf on hot path #949

Closed
opened 2026-03-02 06:10:34 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hibiken/asynq/pull/962
Author: @pior
Created: 11/10/2024
Status: Merged
Merged: 11/11/2024
Merged by: @kamikazechaser

Base: masterHead: str-concat


📝 Commits (1)

  • 2d6d6f4 Use string concat instead of fmt.Sprintf

📊 Changes

2 files changed (+25 additions, -25 deletions)

View changed files

📝 internal/base/base.go (+24 -24)
📝 x/rate/semaphore.go (+1 -1)

📄 Description

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

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hibiken/asynq/pull/962 **Author:** [@pior](https://github.com/pior) **Created:** 11/10/2024 **Status:** ✅ Merged **Merged:** 11/11/2024 **Merged by:** [@kamikazechaser](https://github.com/kamikazechaser) **Base:** `master` ← **Head:** `str-concat` --- ### 📝 Commits (1) - [`2d6d6f4`](https://github.com/hibiken/asynq/commit/2d6d6f45ac08c791a013768b79c25d5319af384b) Use string concat instead of fmt.Sprintf ### 📊 Changes **2 files changed** (+25 additions, -25 deletions) <details> <summary>View changed files</summary> 📝 `internal/base/base.go` (+24 -24) 📝 `x/rate/semaphore.go` (+1 -1) </details> ### 📄 Description ## 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 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-02 06:10:34 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/asynq#949
No description provided.