Avoid per-key allocations in GetProperty - #1121
Open
lahma wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GetPropertyruns once per YAML key during deserialization and usedGetProperties(...).Where(p => p.Name == name), allocating a closure (capturingname) and a LINQ iterator on every call. This replaces it with a manual scan that is allocation-free when the property list is anIReadOnlyList(as it is when it comes fromCachedTypeInspector). 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):
Serialize, untyped-deserialize and parse benchmarks are unchanged with byte-identical allocations (they don't hit this path). Benchmarks live in #1119.