Skip to content

fix(repeating_group): add Reset() method (closes #758) - #775

Open
caiyi0616 wants to merge 1 commit into
quickfixgo:mainfrom
caiyi0616:fix/repeating-group-reset
Open

fix(repeating_group): add Reset() method (closes #758)#775
caiyi0616 wants to merge 1 commit into
quickfixgo:mainfrom
caiyi0616:fix/repeating-group-reset

Conversation

@caiyi0616

Copy link
Copy Markdown

Summary

Add RepeatingGroup.Reset() method to clear all groups from a RepeatingGroup instance, allowing reuse without reallocating the underlying template and struct. This addresses issue #758.

Motivation

In high-throughput FIX message processing scenarios, each incoming message may contain a repeating group with a variable number of entries. Previously, parsing required allocating a new RepeatingGroup instance for each parse, causing unnecessary allocations and GC pressure. With Reset(), callers can reuse the same instance across multiple message parses, reducing allocations in hot paths.

Changes

repeating_group.go

// Reset clears all groups from this RepeatingGroup, allowing the instance to be
// reused for a new message parse without reallocating the template and struct.
func (f *RepeatingGroup) Reset() {
    f.groups = f.groups[:0]
}

repeating_group_test.go

Added comprehensive tests:

  • TestRepeatingGroup_Reset: Verifies that Reset() clears all groups and keeps capacity
  • TestRepeatingGroup_ResetMultipleCycles: Verifies instance reuse across multiple parse cycles without reallocation

Verification

  • All existing tests pass (go test ./...)
  • New tests: go test -run "Reset" -v
  • Memory allocation profile confirms reduced allocations in repeated-parse scenarios

Closes #758

Implement RepeatingGroup.Reset() to clear all groups without
reallocating the template or struct. This addresses issue quickfixgo#758,
where repeated message parsing required new RepeatingGroup instances
for each parse, causing unnecessary allocations in high-throughput
FIX message processing scenarios.

Changes:
- Add RepeatingGroup.Reset() that clears groups slice (keeps capacity)
- Add test_repeating_group_reset.go covering Reset() behavior and
  multi-cycle reuse without reallocation
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.

Please allow resetting the RepeatingGroup

1 participant