Skip to content

[release/9.0] Make GetPropertyCount public and fix its return value - #106576

Merged
carlossanlop merged 5 commits into
release/9.0from
backport/pr-106503-to-release/9.0
Aug 27, 2024
Merged

carlossanlop merged 5 commits into
release/9.0from
backport/pr-106503-to-release/9.0

Conversation

@github-actions

@github-actions github-actions Bot commented Aug 17, 2024 •

Copy link
Copy Markdown
Contributor

Backport of #106503 to release/9.0

/cc @eiriktsarpalis @etemi

Customer Impact

  • Customer reported
  • Found internally

The implementation of the new JsonElement.DeepEquals in .NET 9 makes use of the internal JsonElement.GetPropertyCount() to short-circuit equality checks for two JSON objects. In a subsequent PR for .NET 10 that makes the GetPropertyCount() method public it was discovered that the method reports inaccurate information (the number of total tokens contained within an object as opposed to the number of properties).

While this inaccuracy doesn't impact functional correctness for equality comparison (if two JSON objects are equal, they always contain an equal number of tokens) it does impact performance, as it can force recursive equality checks for objects containing different numbers of properties.

It should be noted that this change adds new API (JsonElement.GetPropertyCount()) which makes testing for the correct behavior possible.

Regression

  • Yes
  • No

Testing

Added unit testing validating that the correct property counts are being returned.

Risk

Low. Fixes a straightforward omission in the calculation of JsonElement object sizes that was not being used until .NET 9.

@ghost

ghost commented Aug 17, 2024

Copy link
Copy Markdown

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

1 similar comment
@ghost

ghost commented Aug 17, 2024

Copy link
Copy Markdown

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

@carlossanlop

Copy link
Copy Markdown
Contributor

All release/9.0 PRs are currently only requiring M2 approval. @artl93 (or maybe @jeffschwMSFT at the moment)?

@jeffschwMSFT jeffschwMSFT left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

approved. please get a code review. this can be merged when ready

@jeffhandley jeffhandley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good and is approved for 9.0 RC2 once CI is green.

@artl93 artl93 added the Servicing-approved Approved for servicing release label Aug 23, 2024
@carlossanlop

Copy link
Copy Markdown
Contributor

All requirements met. Merging now.

@carlossanlop
carlossanlop merged commit 980daff into release/9.0 Aug 27, 2024
@carlossanlop
carlossanlop deleted the backport/pr-106503-to-release/9.0 branch August 27, 2024 17:03
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants