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

Improve serialization #8448

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

Improve serialization #8448

wants to merge 4 commits into from

Conversation

flobernd
Copy link
Member

@flobernd flobernd commented Jan 21, 2025

Changes:

  • Improve custom converter performance.
    • Replace nested JsonSerializer.{Serialize|Deserialize} calls with direct converter access (JsonSerializerOptions.GetConverter -> converter.{Read|Write}) to prevent frequent creation of top-level JSON reader stacks.
    • Prefer direct ValueSpan access instead of allocating intermediate string values (e.g. when comparing property names or parsing/formatting values).
    • Use pre-encoded JsonEncodedText constants for compile-time constant literals (e.g. property names).
    • Use Utf8Parser/Utf8Formatter for primitive value conversions.
    • Envelope-stype marker types like e.g. SourceMarker<T> should only (de-)serialize the wrapped type to prevent unnecessary allocations.
  • Implement round-trip support for all types (limited to all JSON serializable types).
    • Requests
      • Regular requests
      • Requests with required path-parameters.
      • NDJSON requests (IStreamSerializable).
    • Responses
      • Regular responses
      • Dictionary responses
    • Regular classes
    • Unions
    • Enums
    • Internal variants
    • External variants
    • Untagged variants
    • Container variants
    • SortOptions special case

Breaking changes:

  1. None so far

Later:

  • Do not generate custom converters when property attributes are sufficient
  • Serialization AOT support
  • Get rid of ISelfTwoWaySerializable (used for array/dictionary requests/responses)
  • Get rid of ISelfSerializable (used for descriptors)

Related to:

@flobernd flobernd changed the title Serialization refactor Improve serialization Jan 21, 2025
@flobernd flobernd force-pushed the serialization-refactor branch 4 times, most recently from 7b5b26e to 37bf38c Compare January 28, 2025 14:52
@flobernd flobernd force-pushed the serialization-refactor branch from 37bf38c to 844778d Compare January 29, 2025 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant