Skip to content

Avoid per-key allocations in GetProperty - #1121

Open
lahma wants to merge 1 commit into
aaubry:masterfrom
lahma:perf/getproperty-alloc
Open

Avoid per-key allocations in GetProperty#1121
lahma wants to merge 1 commit into
aaubry:masterfrom
lahma:perf/getproperty-alloc

Conversation

@lahma

@lahma lahma commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

GetProperty runs once per YAML key during deserialization and used GetProperties(...).Where(p => p.Name == name), allocating a closure (capturing name) and a LINQ iterator on every call. This replaces it with a manual scan that is allocation-free when the property list is an IReadOnlyList (as it is when it comes from CachedTypeInspector). Matching and duplicate-detection semantics are 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 Δ time Δ alloc
ObjectGraph.DeserializeTyped 40.31 ms / 36.42 MB 36.94 ms / 29.76 MB −8.4% −18.3%
ObjectGraph.RoundtripTyped 69.87 ms / 54.97 MB 70.94 ms / 52.21 MB ~flat −5.0%

Serialize, untyped-deserialize and parse benchmarks are unchanged with byte-identical allocations (they don't hit this path). Benchmarks live in #1119.

GetProperty ran on every YAML key during deserialization and used
`GetProperties(...).Where(p => p.Name == name)`, allocating a closure (capturing name) and a LINQ
iterator per call. Replace with a manual scan that is allocation-free when the property list is an
IReadOnlyList (as it is when it comes from CachedTypeInspector). Matching and duplicate-detection
semantics are 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