Repository navigation
The synchronous ToList reads into pooled chunks, as ToListAsync does - #287
Merged
Merged
Conversation
On a view or a reader, the synchronous `ToList()` grew a list of its own: it allocated the growth as well as the result and rented no pooled array, so the copy-out clearing never reached it. It now writes its rows straight into the chunk chain (its own loop, like the synchronous `ToArray`) and copies them once into a list of exactly their number. A bare `IDataReader` is read through `Fill` into the same chain, as `ToArray` does. No public API changes. Bytes per call, a mapped `DataTable` of `int` rows (0, 1, 1,000, 100,000 rows): `ToList()` 784, 824, 33,152 and 1,049,728 before; 784, 816, 28,784 and 400,808 after. The synchronous `ToArray` is 752, 784, 28,752 and 400,776, so `ToList` is now an array plus the list object. A Release-only test pins that it allocates less than a list that grows; an explicit probe prints the numbers. Tests: every row in order and an exact capacity (none to 20,000), skip and take, a take of zero rents nothing, every array goes back clean, a failure mid-read returns the chain on both the fast path and the bare `IDataReader` path, and a bare `IDataReader`; the synchronous `ToList` joins the terminals of the copy-out clearing tests (it failed them before: it rented nothing). 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.
The synchronous
ToList()of a view or a reader now reads into the pooled chunk chain and copies once, asToListAsyncdoes.It grew a list of its own: the call allocated the growth as well as the result, and rented no pooled array, so the copy-out clearing of the previous change never reached it. It now writes its rows straight into the chain (its own loop, like the synchronous
ToArray, so there is no sink indirection on the hot path) and copies them once into a list of exactly their number. A bareIDataReaderis read throughFillinto the same chain, asToArraydoes it. No public API changes. It was the only collector that grew its own list.Bytes per call
GC.GetAllocatedBytesForCurrentThreadaround one call oftable.Map<int>().ToList()over an in-memoryDataTableofintrows, warmed first, the smallest of 15 runs, in Release. No timing.ToList()beforeToList()afterToArray()ToListis now an array plus the list object (32 bytes) at every size, and below the old shape from one row up. The probeSyncToListAllocationProbe.Probe_BytesPerCallprints the table (explicit); a Release-only test pins that the call allocates less than a list that grows at 1,000 and 100,000 rows (the bytes are exact, so a revert to the old shape, which measures 24 bytes above the hand-written loop, fails it). The timing of chain plus clear against the old list goes in the next timed run.Tests
SkipandTake; a take of zero rents nothing.IDataReaderreads into the same chain, with an exact capacity; a mapper that throws on the third row gives the chain back (checked on the parked chain of a row type no other test uses) and its own exception comes out unchanged, on theDbDataReaderfast path and on the bare path.ToListjoins the terminals of the copy-out clearing tests, for no pool offered,UsePool(true)andUsePool(false). It failed them before this change, because it rented nothing.Checks
dotnet format styleandanalyzersat--severity inforeport nothing on all 14 projects; the docs build is clean.ToArray). Real finding from the test review fixed: the bareIDataReaderpath had no failure test. Not taken: a fixed byte budget for the allocation test (the byte counts are deterministic and the old shape fails the comparison), and removing the!DEBUGgate (it is the pattern of the existingToListAsynctest).Release notes under "Changes since rc.16".
🤖 Generated with Claude Code