[release/9.0] Make GetPropertyCount public and fix its return value - #106576
Merged
Merged
Conversation
…me at every object node
Also added checks for `GetArrayLength`
|
Note regarding the |
1 similar comment
|
Note regarding the |
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis |
Contributor
|
All release/9.0 PRs are currently only requiring M2 approval. @artl93 (or maybe @jeffschwMSFT at the moment)? |
jeffschwMSFT
approved these changes
Aug 21, 2024
jeffschwMSFT
left a comment
Member
There was a problem hiding this comment.
approved. please get a code review. this can be merged when ready
jeffhandley
approved these changes
Aug 21, 2024
jeffhandley
left a comment
Member
There was a problem hiding this comment.
Looks good and is approved for 9.0 RC2 once CI is green.
artl93
approved these changes
Aug 23, 2024
Contributor
|
All requirements met. Merging now. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #106503 to release/9.0
/cc @eiriktsarpalis @etemi
Customer Impact
The implementation of the new
JsonElement.DeepEqualsin .NET 9 makes use of the internalJsonElement.GetPropertyCount()to short-circuit equality checks for two JSON objects. In a subsequent PR for .NET 10 that makes theGetPropertyCount()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
Testing
Added unit testing validating that the correct property counts are being returned.
Risk
Low. Fixes a straightforward omission in the calculation of
JsonElementobject sizes that was not being used until .NET 9.