Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
## 2026-05-27 - Reducing Allocations with bufio.Scanner
**Learning:** Parsing large embedded strings (like blocklists) using `strings.Split` creates a large slice of strings that persists until the loop finishes. This is inefficient for one-time map population.
**Action:** Use `bufio.Scanner` with `strings.NewReader` to process the string line-by-line. This minimizes temporary allocations and is significantly more memory-efficient for large text datasets.
>> Refactored redisChecks to use a preallocated checks map and iterate via a slice instead of a map to reduce memory allocations during Health check operations.
17 changes: 11 additions & 6 deletions internal/handlers/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,24 @@ type HealthStatus struct {

func (h *HealthHandler) Check(c echo.Context) error {
status := "OK"
checks := make(map[string]string)
checks := make(map[string]string, 4)

// Redis checks. These back-ends are required for the service to function,
// so a failure makes the service unready (503), not merely degraded.
redisChecks := map[string]*redis.Client{
"redis_user": core.UserDB,
"redis_token": core.TokenDB,
"redis_rate": core.RateLimitDB,
redisChecks := []struct {
name string
client *redis.Client
}{
{"redis_user", core.UserDB},
{"redis_token", core.TokenDB},
{"redis_rate", core.RateLimitDB},
}

var wg sync.WaitGroup
var mu sync.Mutex
for name, client := range redisChecks {
for _, check := range redisChecks {
name := check.name
client := check.client
wg.Add(1)
go func(name string, client *redis.Client) {
defer wg.Done()
Expand Down
Loading