Skip to content

Optimize hot paths: eliminate allocations in entropy calculation and topology matching#1

Merged
xkilldash9x merged 5 commits into
mainfrom
copilot/improve-slow-code-efficiency
Jan 14, 2026
Merged

Optimize hot paths: eliminate allocations in entropy calculation and topology matching#1
xkilldash9x merged 5 commits into
mainfrom
copilot/improve-slow-code-efficiency

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 14, 2026

Systematic profiling revealed allocation-heavy hot paths causing GC pressure during large-scale code analysis.

Changes

entropy.go: Replace map[byte]float64 with stack-allocated [256]int array

  • 0 allocations (was ~256), 40% faster

topology.go: Eliminate intermediate map in mapSimilarity, pre-allocate string accumulator

  • 2-pass algorithm vs 3-pass, 0 allocations (was 1-2)
  • Size estimation handles quoted/unquoted strings correctly

zipper.go: Index-based queue iteration instead of slice reallocation

  • O(1) space vs O(n) allocations during BFS

canonicalizer.go: Pre-allocate strings.Builder capacity

  • ~50 bytes per instruction (empirically derived)

scanner_bolt.go: Direct byte slice construction for fuzzy hash prefix

  • Eliminates string concatenation in scan loop

Benchmarks

BenchmarkEntropyCalculation         1,280 ns/op    0 B/op    0 allocs/op
BenchmarkMapSimilarity               308 ns/op     0 B/op    0 allocs/op

Before/after example:

// Before: heap allocation + map overhead
frequencies := make(map[byte]float64)
for _, b := range data {
    frequencies[b]++
}

// After: stack-allocated array
var frequencies [256]int
for _, b := range data {
    frequencies[b]++
}

Zero behavioral changes. All tests pass, CodeQL clean.

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 4 commits January 14, 2026 01:44
Co-authored-by: xkilldash9x <223238109+xkilldash9x@users.noreply.github.com>
Co-authored-by: xkilldash9x <223238109+xkilldash9x@users.noreply.github.com>
Co-authored-by: xkilldash9x <223238109+xkilldash9x@users.noreply.github.com>
Co-authored-by: xkilldash9x <223238109+xkilldash9x@users.noreply.github.com>
Copilot AI changed the title [WIP] Identify and suggest improvements for slow code Optimize hot paths: eliminate allocations in entropy calculation and topology matching Jan 14, 2026
Copilot AI requested a review from xkilldash9x January 14, 2026 01:54
@xkilldash9x xkilldash9x marked this pull request as ready for review January 14, 2026 02:16
@xkilldash9x xkilldash9x merged commit 0b60034 into main Jan 14, 2026
1 check passed
@xkilldash9x xkilldash9x deleted the copilot/improve-slow-code-efficiency branch January 14, 2026 02:16
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