Skip to content

Cache the per-property key node when serializing - #1123

Open
lahma wants to merge 1 commit into
aaubry:masterfrom
lahma:perf/cache-key-node
Open

Cache the per-property key node when serializing#1123
lahma wants to merge 1 commit into
aaubry:masterfrom
lahma:perf/cache-key-node

Conversation

@lahma

@lahma lahma commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Serializing a mapping allocated a throwaway ObjectDescriptor for every property of every object, purely to carry the property name as the key scalar. That key node is fully determined by the property's (immutable) name, so this caches it per descriptor. ObjectDescriptor is immutable, so behavior is unchanged — all 1979 unit + spec tests pass; builds on net10.0/net8.0/netstandard2.0/netstandard2.1/net47.

Same-session A/B (net10.0, DefaultJob, MemoryDiagnoser):

Benchmark Baseline This PR Δ alloc
ObjectGraph.SerializeTyped 20.0 MB 17.6 MB −12.0%
SerializationBenchmarks.Serializer 13.23 MB 12.31 MB −7.0%
ObjectGraph.RoundtripTyped 50.99 MB 48.59 MB −4.7%

Time is neutral (the dictionary lookup replaces the per-property allocation). Deserialize/parse benchmarks are unchanged with byte-identical allocations. Benchmarks live in #1119.

Traversing a mapping allocated a throwaway ObjectDescriptor for every property of every object, just
to carry the property name as the key scalar. That node is fully determined by the property's
immutable name, so cache it per descriptor. ObjectDescriptor is immutable, so behavior is unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant