quickfix icon indicating copy to clipboard operation
quickfix copied to clipboard

Reduce memory allocations in message parsing hot paths

Open gurre opened this issue 2 months ago • 0 comments

Changes

Allocation optimizations:

  • sync.Pool for Message objects (AcquireMessage/ReleaseMessage)
  • Pre-allocate RepeatingGroup.groups slice using expectedGroupSize
  • Cache tag ordering closure in RepeatingGroup (was N allocations per Read)

Hot path improvements:

  • GetString: removed FIXString intermediate allocation
  • ConditionallyRequiredFieldMissing: use strconv.Itoa instead of fmt.Sprintf
  • GetTime: fixed recursive RLock by using getBytesNoLock
  • Removed unused getFieldNoLock function

Benchmark Results

Benchmark Before After Improvement
GetString 20.7 ns/op, 24 B/op, 2 allocs 9.4 ns/op, 8 B/op, 1 alloc -54% time, -67% mem
ParseMessageNew 1670 ns/op, 5336 B/op, 28 allocs
ParseMessagePool 482 ns/op, 176 B/op, 2 allocs 3.5x faster, 30x less mem
ParseMessage (reused) 318 ns/op 321 ns/op no regression
RepeatingGroupRead 1198 ns/op, 870 B/op, 11 allocs

gurre avatar Dec 05 '25 10:12 gurre