Skip to content

Avoid initializing every session event type on first deserialization #2777

Description

@davkean

SessionEvent.FromJson deserializes through the polymorphic base JsonTypeInfo. On the first event, System.Text.Json configures metadata for every derived session event type before returning the one concrete event that was received.

A cold-process console reproduction that deserializes one user.message event shows these medians across 15 processes:

Target Current Discriminator dispatch prototype
.NET Framework 4.7.2 5,466 ms 315 ms
.NET 8 512 ms / 5.09 MB 139 ms / 0.42 MB

The prototype reads the existing type discriminator and deserializes with only the matching source-generated concrete JsonTypeInfo. Unknown and missing discriminators continue to produce the base SessionEvent, preserving forward compatibility.

The expected behavior is for first-event deserialization to configure only the metadata required by the received event type, without changing known, unknown, union, or forward-compatible event semantics.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions