From a90c5dd6f3e632907ae4994058e549c8071ef769 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 11 May 2026 12:23:43 +0800 Subject: [PATCH] perf: in-place filtering in RateLimiter to reduce GC pressure --- internal/platform/httpx/limits.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/platform/httpx/limits.go b/internal/platform/httpx/limits.go index a119705..eb56fe5 100644 --- a/internal/platform/httpx/limits.go +++ b/internal/platform/httpx/limits.go @@ -63,14 +63,15 @@ func (rl *RateLimiter) Allow(key string) bool { sw.mu.Lock() defer sw.mu.Unlock() - // Remove expired tokens - var valid []time.Time + // Remove expired tokens using in-place filtering to avoid GC pressure. + n := 0 for _, t := range sw.tokens { if t.After(cutoff) { - valid = append(valid, t) + sw.tokens[n] = t + n++ } } - sw.tokens = valid + sw.tokens = sw.tokens[:n] if len(sw.tokens) >= rl.limit { return false