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

Avoid string allocation and improve performance of JsonProperty.WriteTo #90074

Merged
merged 13 commits into from
Sep 22, 2023

Commits on Aug 5, 2023

  1. Avoid string allocation in WriteTo when possible.

    System.Text.Json.JsonProperty.WriteTo uses get_Name, calling
    JsonElement.GetPropertyName() which would allocate a string.
    
    Use ReadOnlySpan<byte> from the underlying UTF8 json, when possible,
    by adding helper methods into JsonDocument & JsonElement.
    
    Fix dotnet#88767
    karakasa committed Aug 5, 2023
    Configuration menu
    Copy the full SHA
    ad30f54 View commit details
    Browse the repository at this point in the history
  2. Avoid alloc in unescaping & escaping.

    Current code unescapes & escapes property names and uses ToArray.
    Avoid alloc by adding internal GetRaw/WriteRaw methods.
    karakasa committed Aug 5, 2023
    Configuration menu
    Copy the full SHA
    41f5c37 View commit details
    Browse the repository at this point in the history

Commits on Aug 6, 2023

  1. Fix bugs on escaped property names

    Original code doesn't handle GetRaw/WriteRaw on escaped
    property names correctly.
    karakasa committed Aug 6, 2023
    Configuration menu
    Copy the full SHA
    d4d84b1 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    c368aa3 View commit details
    Browse the repository at this point in the history
  3. Further avoid alloc by inlining GetUnescapedSpan

    Allocations are further avoided when the property name is shorter than
    JsonConstants.StackallocByteThreshold, by inlining
    JsonReaderHelper.GetUnescapedSpan.
    karakasa committed Aug 6, 2023
    Configuration menu
    Copy the full SHA
    c5c5593 View commit details
    Browse the repository at this point in the history

Commits on Aug 7, 2023

  1. Move writing logic to JsonElement;

    Shorten names of new methods;
    Add a test of writing out special names.
    karakasa committed Aug 7, 2023
    Configuration menu
    Copy the full SHA
    1528bf3 View commit details
    Browse the repository at this point in the history

Commits on Aug 11, 2023

  1. Move logic into JsonDocument

    karakasa committed Aug 11, 2023
    Configuration menu
    Copy the full SHA
    5690487 View commit details
    Browse the repository at this point in the history
  2. fix format

    karakasa committed Aug 11, 2023
    Configuration menu
    Copy the full SHA
    b6c8606 View commit details
    Browse the repository at this point in the history
  3. fix format 2

    karakasa committed Aug 11, 2023
    Configuration menu
    Copy the full SHA
    9644915 View commit details
    Browse the repository at this point in the history
  4. improve comment

    karakasa committed Aug 11, 2023
    Configuration menu
    Copy the full SHA
    63da811 View commit details
    Browse the repository at this point in the history

Commits on Sep 21, 2023

  1. removed unused stub

    karakasa committed Sep 21, 2023
    Configuration menu
    Copy the full SHA
    df8e6fa View commit details
    Browse the repository at this point in the history
  2. added assertion

    karakasa committed Sep 21, 2023
    Configuration menu
    Copy the full SHA
    d2fd37c View commit details
    Browse the repository at this point in the history
  3. removed unnecessary test

    karakasa committed Sep 21, 2023
    Configuration menu
    Copy the full SHA
    ecca233 View commit details
    Browse the repository at this point in the history