Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/9.0] Update the JSON schema exporter to reuse schemas more aggressively. #108800

Merged
merged 1 commit into from
Oct 18, 2024

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Oct 11, 2024

Backport of #108764 to release/9.0

/cc @eiriktsarpalis

Customer Impact

  • Customer reported
  • Found internally

A customer reported that generating a JSON schema for typeof(XElement) results in explosive memory growth due to the immense complexity of its underlying type graph. This is caused by the fact that JsonSchemaExporter uses a very conservative schema reuse policy via the $ref keyword, reserving it only for cases where a cycle has been detected in the type graph. This in turn results in a high degree of duplication in clique-like type graphs contributing to exponential memory consumption.

This PR addresses the issue by applying a more aggressive schema reuse policy: if a schema for a node in the graph has been generated, subsequent occurrences will always produce schemas pointing to the original occurrence regardless of its location. This effectively bounds the size of the generated document to $\mathcal O(n)$ where $n$ denotes the number of .NET members occurring in the type graph.

Regression

  • Yes
  • No

Testing

Added unit testing validating the impacted use case.

Risk

Moderate. Makes a last-minute change to the schema generation algorithm which carries risk. Changes what JSON schema is being produced under certain circumstances, even though the new outputs are semantically equivalent to the original outputs.

Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.

@eiriktsarpalis eiriktsarpalis self-assigned this Oct 11, 2024
@eiriktsarpalis eiriktsarpalis added the Servicing-consider Issue for next servicing release review label Oct 11, 2024
@eiriktsarpalis eiriktsarpalis added this to the 9.0.0 milestone Oct 11, 2024
@eiriktsarpalis eiriktsarpalis requested a review from jozkee October 11, 2024 18:37
@rbhanda rbhanda added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Oct 15, 2024
@ericstj ericstj merged commit 83d152c into release/9.0 Oct 18, 2024
86 of 90 checks passed
@jeffhandley jeffhandley deleted the backport/pr-108764-to-release/9.0 branch October 18, 2024 19:57
@github-actions github-actions bot locked and limited conversation to collaborators Nov 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Text.Json Servicing-approved Approved for servicing release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants