Repository navigation
Add ToArrayAsync and ToImmutableArrayAsync on a DbDataReader - #285
Merged
Merged
Conversation
Siblings of the transform form of `ToListAsync` on `DbDataReader`: each reads the remaining rows of the current result set through an asynchronous transform into pooled chunks and copies them once, into an array of exactly their number. On .NET 8 and later the immutable array wraps that array and is not copied again; on .NET Standard it is a copy. The three share one private core, specialized per result by a struct type argument (the build the mapped terminals use), so none has a closure. `ToListAsync` keeps its behavior, including the guards inside the returned task. Tests: every row in order and the exact length (none, one, a few, thousands), the null guards (in the returned task), a transform that throws and a cancel (the chain is parked again after each), for the three terminals; and bytes per call against an `ImmutableArray` builder of unknown capacity, with an explicit probe that prints the numbers. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.
Adds
ToArrayAsyncandToImmutableArrayAsyncon aDbDataReader, beside the transform form ofToListAsync.Each reads the remaining rows of the current result set through an asynchronous transform into pooled chunks and copies them once, into an array of exactly their number. On .NET 8 and later the immutable array wraps that array and is not copied again; on .NET Standard it is a copy (there is no way to wrap an array there).
The three share one private core, specialized per result by a struct type argument (the build the mapped terminals already use), so none has a closure.
ToListAsynckeeps its behavior, including the argument guards inside the returned task. The two new members are inPublicAPI.Unshipped.txtand in the release notes under "Changes since rc.16".Bytes per call against a builder of unknown capacity
GC.GetAllocatedBytesForCurrentThreadaround one call, warmed first, the smallest of 15 runs, in Release, over an in-memoryDataTableReader(itsReadAsyncfinishes at once and allocates nothing). "Net" is the bytes less those of reading the rows alone. No timing.ToImmutableArrayAsync(net)ImmutableArray.CreateBuilder<int>()+ToImmutable()(net)ToArrayAsync(net)List<int>+ToArray()(net)The builder never wins. At 100,000 rows the chunk path allocates exactly the result (4 bytes a row); the builder allocates its growth as well as the final copy. The explicit probe
ReaderCollectAllocationProbe.Probe_BytesPerCallprints the table; a Release-only test pins that the chunk path allocates less than a builder at 1,000 and 100,000 rows.Tests
ArgumentNullExceptionwith the right parameter name, thrown inside the returned task (the calls are made outside the assert, so a throw at the call would fail the test).ReadAsynchonors the token, for all three methods: the task faults or is cancelled, and the chunk chain is parked again (read through the one spare slot of a row type no other test uses).Checks
dotnet format styleandanalyzersat--severity inforeport nothing on all 14 projects; the docs build is clean.🤖 Generated with Claude Code