Skip to content

Conversation

@reakaleek
Copy link
Member

@reakaleek reakaleek commented Sep 24, 2025

Changes

Extract applies_to yaml parsing into its own class and reuse it in all the places.

Also, add memoization so we don't parse the same input over and over again.

@reakaleek reakaleek changed the base branch from main to feature/applies-switch September 24, 2025 20:22
@reakaleek reakaleek force-pushed the feature/optimize-applicable-to-parsing branch from 8c0dff1 to 39a7320 Compare September 24, 2025 20:24
@reakaleek reakaleek requested a review from Copilot September 24, 2025 20:33
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR optimizes the parsing of applies_to YAML definitions by introducing a centralized parser with memoization capabilities. The change eliminates code duplication and improves performance by caching parsed results.

Key Changes:

  • Created a new ApplicableToParser class that provides centralized YAML parsing with memoization
  • Replaced direct YamlSerialization.Deserialize calls across multiple files with the new parser
  • Updated test expectations to reflect changes in HTML output formatting

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/Elastic.Documentation/AppliesTo/ApplicableToParser.cs New parser class with memoization using ConcurrentDictionary
src/Elastic.Markdown/Myst/Roles/AppliesTo/AppliesToRole.cs Updated to use centralized parser instead of direct deserialization
src/Elastic.Markdown/Myst/Directives/DirectiveHtmlRenderer.cs Replaced local parsing method with centralized parser
src/Elastic.Markdown/Myst/Directives/AppliesSwitch/AppliesSwitchBlock.cs Simplified sync key generation using new parser
src/Elastic.Markdown/Myst/CodeBlocks/EnhancedCodeBlockParser.cs Updated applies_to directive processing to use new parser
tests/Elastic.Markdown.Tests/Directives/ApplicabilitySwitchTests.cs Added import for new AppliesTo namespace
tests/authoring/Inline/AppliesToRole.fs Updated test expectations for HTML output format changes

@reakaleek reakaleek force-pushed the feature/optimize-applicable-to-parsing branch from 6c8a96c to b41dcd3 Compare September 24, 2025 21:01
@reakaleek reakaleek marked this pull request as ready for review September 24, 2025 21:01
@reakaleek reakaleek requested a review from a team as a code owner September 24, 2025 21:01
@reakaleek reakaleek requested a review from Mpdreamz September 24, 2025 21:01
/// </summary>
public static class ApplicableToParser
{
private static readonly ConcurrentDictionary<string, ApplicableTo?> ParsedCache = new();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conflicted about memoization here.

Deserialization should be fast (the serialization routines get source generated at build time) and these objects are typically short lived so should be GC'd away quickly too.

This does keep fewer instances around but I wonder how many cache hits we actually get with folks writing the yaml in different orders.

Applicability.TryParse() might be worth memoizing since it has a much higher chance of hitting the cache. But even there there are so many version lifecycle permutations around memoizing might eat up more memory then its worth easing GC pressure.

Base automatically changed from feature/applies-switch to main September 25, 2025 09:23
@reakaleek reakaleek requested a review from a team as a code owner September 25, 2025 09:23
@reakaleek reakaleek closed this Sep 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants