perf: pre-size setup dispatch tables to FastMockInteractions member count#773
Conversation
…ount The outer table started at size memberId+1, forcing a realloc + Array.Copy when a later setup targeted a higher-numbered member. The generator already knows the total member count and exposes it via FastMockInteractions.Buffers.Length, so use that as the initial size on first allocation. Subsequent setups never need to grow the outer table. Saves one outer-table allocation plus the Array.Copy per fresh mock when setups touch multiple members. Applies to the method, indexer, property, and event dispatch tables.
There was a problem hiding this comment.
Pull request overview
This PR improves setup registration performance in MockRegistry by pre-sizing the per-member setup dispatch tables using the generator-known mocked member count (via FastMockInteractions.Buffers.Length), avoiding a first-time resize/copy when setups target higher-numbered member ids.
Changes:
- Add a
GetMemberCountHint()helper that returnsFastMockInteractions.Buffers.Lengthwhen available. - Use the hint on first allocation of method/indexer/property/event setup dispatch tables to reduce reallocations and
Array.Copy.
🚀 Benchmark ResultsDetails
Details
Details
Details
Details
Details
|
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
… FastMockInteractions member count (#773) by Valentin Breuß
… FastMockInteractions member count (#773) by Valentin Breuß
|
This is addressed in release v3.2.0. |



The outer table started at size memberId+1, forcing a realloc + Array.Copy when a later setup targeted a higher-numbered member. The generator already knows the total member count and exposes it via FastMockInteractions.Buffers.Length, so use that as the initial size on first allocation. Subsequent setups never need to grow the outer table.
Saves one outer-table allocation plus the Array.Copy per fresh mock when setups touch multiple members. Applies to the method, indexer, property, and event dispatch tables.