⚡ Bolt: optimize multi-regional listings to be lock-free and pre-allocated - #47
⚡ Bolt: optimize multi-regional listings to be lock-free and pre-allocated#47JulienBreux wants to merge 1 commit into
Conversation
…cated This commit refactors the listAllRegions concurrent listing logic in the service, domainmapping, job, and workerpool packages. Rather than using a sync.Mutex to append results concurrently (which causes mutex contention and dynamic slice allocation churn), it uses a pre-allocated slice of slices pattern. Results are stored concurrently in pre-allocated sub-slices. Finally, a single flat slice is pre-allocated with the exact total length, and sub-slices are appended, completely eliminating lock contention and slice allocation churn. Co-authored-by: JulienBreux <964330+JulienBreux@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
💡 What:
Implemented a lock-free, pre-allocated map-reduce pattern with a slice of slices ([][]T) instead of sync.Mutex and concurrent append across service, domainmapping, job, and workerpool packages for multi-regional listings (listAllRegions).
🎯 Why:
Querying all 24 GCP locations concurrently introduces high mutex contention as 24 goroutines race to acquire the lock and append their results to a single shared slice. Additionally, dynamic slices continually resize and reallocate on the heap under concurrency.
📊 Impact:
🔬 Measurement:
Verified with package-specific unit tests and micro-benchmarks (go test -bench=BenchmarkListAllRegions -benchmem ./internal/run/api/service/...) and verified correctness with the full test suite (make test).
PR created automatically by Jules for task 9506558127271501064 started by @JulienBreux