Skip to content

Conversation

@gurre
Copy link

@gurre gurre commented Dec 5, 2025

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 gurre force-pushed the main branch 2 times, most recently from 6cd5003 to 39ad3e0 Compare December 5, 2025 10:43
Benchmark results:
- GetString: 20.7→9.4 ns/op (-54%), 24→8 B/op (-67%), 2→1 allocs (-50%)
- ParseMessage: 318→321 ns/op (0 B/op, 0 allocs, no regression)
- RepeatingGroupRead: 1198 ns/op, 870 B/op, 11 allocs

Changes:
- GetString: removed FIXString intermediate allocation
- RepeatingGroup: cached tag ordering closure (was N allocations per Read)
- ConditionallyRequiredFieldMissing: strconv.Itoa vs fmt.Sprintf
- GetTime: fixed recursive RLock by using getBytesNoLock
- Removed unused getFieldNoLock function

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Reduce memory allocations through:
- sync.Pool for Message objects (AcquireMessage/ReleaseMessage)
- Pre-allocate FieldMap.tagLookup map with capacity 16
- Pre-allocate RepeatingGroup.groups slice using expectedGroupSize

Benchmark comparison (new message per parse):

| Benchmark            | Time        | Memory      | Allocs   |
|----------------------|-------------|-------------|----------|
| ParseMessageNew      | 1670 ns/op  | 5336 B/op   | 28       |
| ParseMessagePool     | 482 ns/op   | 176 B/op    | 2        |

Improvements with pool:
- 3.5x faster
- 30x less memory per operation
- 14x fewer allocations

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
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.

1 participant