Skip to content

Minor optimizations: pre-allocate maps in event paths, consolidate metrics#174

Open
Copilot wants to merge 8 commits intomainfrom
copilot/reduce-allocations-and-spinning
Open

Minor optimizations: pre-allocate maps in event paths, consolidate metrics#174
Copilot wants to merge 8 commits intomainfrom
copilot/reduce-allocations-and-spinning

Conversation

Copy link
Contributor

Copilot AI commented Feb 13, 2026

Changes

Map pre-allocation in hot paths

  • event.go: make(map[string]string, 6) for event headers (exact size known)
  • outbox.go: make(map[Header]string, len(outboxRecord.Headers)) (dynamic sizing)

Consolidated duplicate metric recording (timeout.go)

// Before: recorded twice (error path + success path)
if err != nil {
    metrics.ProcessLatency.WithLabelValues(...).Observe(...)
    return err
}
metrics.ProcessLatency.WithLabelValues(...).Observe(...)

// After: single call
metrics.ProcessLatency.WithLabelValues(...).Observe(...)
if err != nil { return err }

Benchmarks added (performance_test.go)

  • Map allocation patterns
  • Metric label caching
  • String operations

Context

Profiling revealed core workflow already well-optimized:

  • 98% of allocations in test infrastructure (memrecordstore), not production code
  • Run pooling via sync.Pool already implemented
  • No spinning issues—all loops use proper blocking/delays

Changes prevent minor inefficiencies and improve code clarity.


✨ 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 6 commits February 13, 2026 16:43
Co-authored-by: andrewwormald <20083774+andrewwormald@users.noreply.github.com>
Co-authored-by: andrewwormald <20083774+andrewwormald@users.noreply.github.com>
Co-authored-by: andrewwormald <20083774+andrewwormald@users.noreply.github.com>
Co-authored-by: andrewwormald <20083774+andrewwormald@users.noreply.github.com>
Co-authored-by: andrewwormald <20083774+andrewwormald@users.noreply.github.com>
Co-authored-by: andrewwormald <20083774+andrewwormald@users.noreply.github.com>
Copilot AI changed the title [WIP] Scan codebase for performance improvements through tests Perf: reduce allocations in event processing hot paths Feb 13, 2026
Copilot AI requested a review from andrewwormald February 13, 2026 17:06
@andrewwormald andrewwormald marked this pull request as ready for review February 16, 2026 12:02
Co-authored-by: andrewwormald <20083774+andrewwormald@users.noreply.github.com>
Copilot AI changed the title Perf: reduce allocations in event processing hot paths Remove non-standard performance documentation files Feb 16, 2026
@sonarqubecloud
Copy link

Copilot AI changed the title Remove non-standard performance documentation files Minor optimizations: pre-allocate maps in event paths, consolidate metrics Feb 16, 2026
Copilot AI requested a review from andrewwormald February 16, 2026 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments