From 8301b1f9ceeb74d335902203a64652c9e57fff81 Mon Sep 17 00:00:00 2001 From: Levi Date: Fri, 18 Sep 2026 23:22:57 +0800 Subject: [PATCH] feat(http): accelerate connection expansion with squared batches (#1530) --- internal/protocol/http/fetcher.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/protocol/http/fetcher.go b/internal/protocol/http/fetcher.go index 7922c003..89804ce3 100644 --- a/internal/protocol/http/fetcher.go +++ b/internal/protocol/http/fetcher.go @@ -150,7 +150,7 @@ type slowStartController struct { totalLaunched int batchPending int // Connections in current batch waiting for HTTP response batchReady int // Connections in current batch that succeeded - nextBatchSize int // Next batch size: 1, 2, 4, 8... + nextBatchSize int // Next batch size: 1, 2, 4, 16, 256... (capped) expansionCh chan struct{} // Signal to trigger next expansion paused bool // Pause expansion (e.g., on 429) } @@ -229,7 +229,15 @@ func (s *slowStartController) commitBatch(count int) { defer s.mu.Unlock() s.totalLaunched += count - s.nextBatchSize = s.nextBatchSize * 2 // Exponential growth: 1, 2, 4, 8... + if s.nextBatchSize == 1 { + // Bootstrap growth: squaring one would never increase the batch size. + s.nextBatchSize = min(2, s.maxConnections) + } else if s.nextBatchSize > s.maxConnections/s.nextBatchSize { + // Cap before multiplying to avoid integer overflow. + s.nextBatchSize = s.maxConnections + } else { + s.nextBatchSize *= s.nextBatchSize + } s.batchPending = count s.batchReady = 0 }