Skip to content

Refactor ShapeResult for less allocations.#18867

Open
gvkries wants to merge 2 commits intomainfrom
gvkries/shaperesult
Open

Refactor ShapeResult for less allocations.#18867
gvkries wants to merge 2 commits intomainfrom
gvkries/shaperesult

Conversation

@gvkries
Copy link
Member

@gvkries gvkries commented Feb 18, 2026

This pull request refactors and enhances the ShapeResult class in ShapeResult.cs to improve performance, memory efficiency, and code clarity. The main changes include optimizing how display type locations are stored, improving the async predicate evaluation logic, and reorganizing method definitions for better structure.

Performance and Memory Optimizations:

  • Optimized storage for display type locations: Instead of always allocating a dictionary for display type/location pairs, the code now stores up to two pairs in dedicated fields (_firstDisplayType, _firstLocation, _secondDisplayType, _secondLocation) before falling back to a dictionary for additional pairs. This reduces memory allocations for common cases with only one or two display types. [1] [2]

API and Usability Improvements:

  • Refactored fluent API methods (e.g., Prefix, Location, Displaying, Processing, Name, Differentiator, OnGroup, Cache, RenderWhen) to appear before the core implementation logic, improving code organization and discoverability. [1] [2]

Async Predicate Handling:

  • Improved handling of the RenderWhen predicate so that if the predicate completes synchronously, the result is used immediately, otherwise it is awaited asynchronously. This avoids unnecessary async state machine overhead when possible.

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

Comments