Skip to content

Refactor Zone shape methods for efficient async rendering#19324

Open
gvkries wants to merge 2 commits into
mainfrom
gvkries/zoneshapes-perf
Open

Refactor Zone shape methods for efficient async rendering#19324
gvkries wants to merge 2 commits into
mainfrom
gvkries/zoneshapes-perf

Conversation

@gvkries

@gvkries gvkries commented Jun 2, 2026

Copy link
Copy Markdown
Member

This pull request refactors the Zone and ContentZone shape methods in ZoneShapes.cs to optimize asynchronous rendering and improve resource management. The main changes include eliminating unnecessary async/await usage for synchronous paths, introducing efficient enumerator handling to minimize allocations, and ensuring proper disposal of enumerators. Additionally, the code now uses consistent casing for injected parameters and local variables.

Asynchronous rendering and performance improvements

  • Refactored the Zone and ContentZone methods to avoid unnecessary async/await usage when all ShapeExecuteAsync tasks complete synchronously, returning a completed Task directly for improved performance. Added fast-path and slow-path execution logic to minimize allocations and context switches. [1] [2]

  • Introduced helper methods ZoneAwaited and ContentZoneAwaited to handle asynchronous iteration only when necessary, ensuring efficient rendering of shapes and proper disposal of enumerators. [1] [2]

Code consistency and cleanup

  • Standardized casing of injected parameters and local variables, e.g., using displayAsync and shapeFactory instead of DisplayAsync and ShapeFactory, for consistency throughout the codebase. [1] [2] [3]

  • Moved grouped rendering logic into a separate helper method ContentZoneGroupedAsync for clarity and maintainability.

  • Ensured enumerators are always disposed in both fast and slow paths to prevent resource leaks. [1] [2]

Refactored Zone and ContentZone methods to use manual enumerator logic for more efficient asynchronous shape rendering. Extracted grouped rendering logic in ContentZone to a new static method, clarified grouping/ordering, and ensured proper enumerator disposal. This improves performance and code organization while preserving existing behavior.
Comment thread src/OrchardCore/OrchardCore.DisplayManagement/Zones/ZoneShapes.cs
Comment thread src/OrchardCore/OrchardCore.DisplayManagement/Zones/ZoneShapes.cs
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.

2 participants