-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Cleanup exception throwing in Utf8JsonWriter #115702
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 refactors exception throwing helpers in Utf8JsonWriter and related components to remove unused helpers, improve JIT optimization by marking throw methods as not-returning, and consolidate duplicated code.
- Refactored throw helper methods to use new patterns (e.g. GetValidateStartFailedException)
- Replaced ValidatePropertyAndDepth calls with separate property and depth validations
- Updated Utf8JsonReader and MultiSegment handling to follow the new exception patterns
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.cs | Refactored property getters and exception throwing methods |
| src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Raw.cs | Updated calls to throw helpers for raw value validation |
| src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Helpers.cs | Consolidated validation helpers for writing values |
| src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.String.cs | Updated property and value validations in string writing methods |
| src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Helpers.cs | Replaced ValidatePropertyNameAndDepth with separate validations |
| src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Bytes.cs | Replaced property name length validation calls with updated methods |
| src/libraries/System.Text.Json/src/System/Text/Json/Writer/JsonWriterHelper.cs | Removed unused composite validation methods |
| src/libraries/System.Text.Json/src/System/Text/Json/ThrowHelper.cs | Removed redundant throw helpers and updated exception construction patterns |
| src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.cs | Updated literal validation to use new exception patterns |
| src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.MultiSegment.cs | Adjusted multi-segment literal validation to use scoped Span parameters |
| src/libraries/System.Text.Json/src/Resources/Strings.resx | Removed obsolete string resources |
src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.MultiSegment.cs
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.MultiSegment.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, but I think I need to better understand what the motivation for filing this PR is. As it stands I think this should be split into at least two separate PRs (one eliminating dead code, and one proposing changes to the helpers) so that each can be reviewed in it own merits.
|
There's not much dead code actually, only the 3 strings (and 3 throw helpers). Everything else is about removing |
Yes, we like to see numbers for any perf related changes. |
|
I was waiting on #115918, but I guess I could get some perf numbers regardless of that issue. |
|
I addressed the feedback, but this PR now depends on #118280 getting merged first. Will gather some perf numbers also now. |
|
@MihuBot benchmark System.Text.Json |
This addresses #111332 (comment)