Skip to content
This repository was archived by the owner on Mar 15, 2026. It is now read-only.

Optimize performance bottlenecks in adaptive concurrency, storage, and scoring#4

Closed
Copilot wants to merge 3 commits intomainfrom
copilot/improve-slow-code-efficiency
Closed

Optimize performance bottlenecks in adaptive concurrency, storage, and scoring#4
Copilot wants to merge 3 commits intomainfrom
copilot/improve-slow-code-efficiency

Conversation

Copy link
Contributor

Copilot AI commented Nov 12, 2025

Identified and fixed inefficient algorithms and memory allocation patterns causing unnecessary O(n) operations and excessive GC pressure during scoreboard generation and participant management.

Changes

Fixed P95 percentile calculation in adaptive concurrency

  • Before: Approximated as max * 0.8 (inaccurate)
  • After: Proper sorting-based percentile calculation
  • Impact: Accurate API concurrency adjustments under load
// Old: wrong percentile
cutoff := time.Duration(float64(maxTime) * 0.8)

// New: actual 95th percentile
sortedTimes := make([]time.Duration, len(window))
copy(sortedTimes, window)
sort.Slice(sortedTimes, func(i, j int) bool { return sortedTimes[i] < sortedTimes[j] })
return sortedTimes[int(float64(len(sortedTimes)) * 0.95)]

Optimized in-memory storage with O(1) name lookups

  • Before: O(n) linear search through all participants for duplicate names
  • After: Added participantsByName hash map index
  • Impact: Name validation scales from O(n) to O(1)

Pre-allocated maps and slices

  • scoring/calculator.go: Pre-size problem ID map with capacity hint
  • storage/in_memory.go: Pre-allocate slice capacity in fetchStartingProblems
  • Impact: Reduced reallocation overhead and GC pressure

Memory pooling for string builders

  • bot/scoreboard.go: Reuse string builders from performance pool with capacity hints
  • Impact: Eliminates repeated allocations during scoreboard formatting

Added HTTP status code constants

  • Replaced magic numbers (404, 429, 500) with named constants
  • Removed duplicate HTTPServerErrorThreshold definition
Original prompt

Identify and suggest improvements to slow or inefficient code


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits November 12, 2025 04:55
Co-authored-by: AndyH0ng <60703412+AndyH0ng@users.noreply.github.com>
Co-authored-by: AndyH0ng <60703412+AndyH0ng@users.noreply.github.com>
Copilot AI changed the title [WIP] Identify and suggest improvements to inefficient code Optimize performance bottlenecks in adaptive concurrency, storage, and scoring Nov 12, 2025
Copilot AI requested a review from AndyH0ng November 12, 2025 05:08
@AndyH0ng AndyH0ng closed this Dec 20, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants