Pre-size LIST results during materialization - #343
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #343 +/- ##
===========================================
- Coverage 87.59% 87.53% -0.06%
===========================================
Files 77 77
Lines 3143 3154 +11
Branches 466 469 +3
===========================================
+ Hits 2753 2761 +8
- Misses 276 278 +2
- Partials 114 115 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This pull request optimizes LIST/ARRAY materialization in the DuckDB.NET data reader by pre-sizing List<T> instances using DuckDB’s known list length, reducing allocations and repeated reflection overhead during reads.
Changes:
- Adds a regression test asserting
List<int>results are created with initial capacity equal to the list length. - Introduces a cached, reader-local factory path for
List<T>to constructnew List<T>(capacity)during list materialization. - Preserves the existing reflection-based fallback for non-
List<T>collection targets.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| DuckDB.NET.Test/DuckDBDataReaderListTests.cs | Adds a test verifying list capacity is pre-sized during materialization. |
| DuckDB.NET.Data/DataChunk/Reader/ListVectorDataReader.cs | Implements cached List<T> factory creation and uses DuckDB-provided length as initial capacity. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
I'm not sure whether it's worth it cache the factory and additional more reflection to operate it. It'll probably be cleaner and easier to just switch on the type of the return list and explicitly create a new list of that type if there is a match |
Problem
LIST values are materialized into an empty
List<T>and grown as each item is added. That creates avoidable backing-array allocations and repeats reflective construction for every row.Solution
Create normal
List<T>results through a reader-local generic factory and pass DuckDB's known list length as the initial capacity. Custom collection targets keep the existing fallback.Benchmark
100,000 rows with a 16-item
List<int>, median of 7 runs after warmup:Tests