perf: enumerate result pages without boxing - #50
Open
msallin wants to merge 1 commit into
Open
Conversation
SvgResult and PngResult forwarded GetEnumerator to the list behind their Pages property, which hands its enumerator back as an IEnumerator<T> and so boxes the struct: 80 bytes per pass over an SVG and a PNG result. A struct enumerator, which foreach binds to in preference to the interface, removes that. Both the foreach path and the interface path go through it, so the two agree on how an exhausted or not-yet-started enumerator behaves. Binary-breaking: a return type is part of the method signature and foreach binds to the concrete method, so an assembly compiled against an earlier version has to be recompiled. Source-compatible.
msallin
force-pushed
the
perf/result-struct-enumerators
branch
from
September 6, 2026 19:51
28f2ddc to
8cd4ac1
Compare
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.
SvgResultandPngResultforwardedGetEnumerator()to the list behind theirPagesproperty, which hands its enumerator back as anIEnumerator<T>and so boxes the struct: 80 bytes per pass over an SVG and a PNG result. A struct enumerator, whichforeachbinds to in preference to the interface, removes that. Both theforeachpath and the interface path go through it, so the two agree.Adds one public type,
PageEnumerator<T>. It cannot be hidden: a public method may not return a less accessible type.Binary-breaking, and wider than it looks. A return type is part of the method signature and
foreachbinds to the concrete method, so every already-compiledforeachover a result-typed variable throwsMissingMethodExceptionuntil recompiled, not just code that namedIEnumerator<T>itself. Source-compatible; LINQ,Countand the indexer are unaffected. Needs a version bump rather than a patch, and is recorded in RELEASENOTES.Tests: zero allocations across a pass over both result types, which fails at exactly 80 bytes without the change, plus agreement between the struct path, the indexer and LINQ.
58/58 pass, clean on net8/9/10.