Description
FixExponentNotation processes data character by character using append-based byte accumulation, with frequent slice reallocation. Each candidate number triggers a strconv.ParseFloat call. The overall approach is 2-3x slower than necessary.
Evidence
File: pkg/codec/echoreplay.go:333-411
func FixExponentNotation(data []byte) []byte {
var result []byte
// byte-by-byte iteration
for i := 0; i < len(data); i++ {
// character-by-character append to result
result = append(result, data[i])
// ...
// ParseFloat on every candidate number
f, err := strconv.ParseFloat(numStr, 64)
formatted := strconv.FormatFloat(f, 'f', -1, 64)
// ...
}
}
Each append may trigger reallocation. Each number candidate triggers float parsing even when no exponent notation is present.
Impact
Conversion performance bottleneck. This function runs on every frame during legacy format conversion. The byte-by-byte approach with frequent reallocation makes it a measurable hot spot on large replay files.
Suggested Fix
- Pre-allocate
result with make([]byte, 0, len(data))
- Use regex to find exponent-notation numbers, only parse those
- Copy non-matching regions in bulk with
copy() or append(result, data[start:end]...)
🤖 Filed by Metis
Description
FixExponentNotationprocesses data character by character using append-based byte accumulation, with frequent slice reallocation. Each candidate number triggers astrconv.ParseFloatcall. The overall approach is 2-3x slower than necessary.Evidence
File:
pkg/codec/echoreplay.go:333-411Each
appendmay trigger reallocation. Each number candidate triggers float parsing even when no exponent notation is present.Impact
Conversion performance bottleneck. This function runs on every frame during legacy format conversion. The byte-by-byte approach with frequent reallocation makes it a measurable hot spot on large replay files.
Suggested Fix
resultwithmake([]byte, 0, len(data))copy()orappend(result, data[start:end]...)🤖 Filed by Metis