How each way of reading rows ranks
Twenty columns, 1,000 rows, the same synthetic reader for every variant. Reader-open time is the time from ExecuteReader until the reader closes, and it is the number that matters most: it is how long the connection is held. Total time and allocations come second.
Reader-open time
Shorter is better. Lower bars hold the connection for less time.
Total time per call
Where this is much longer than reader-open time, work happens after the reader closes (the "after close" variants).
Memory allocated per call
The RowMap plan and the hand-written selector allocate the same bytes: the list and one object per row. A row class plus Select allocates about twice that.
Cost grows with the number of columns
Total time at 1,000 rows across widths 1, 3, 5, 10 and 20. Every approach grows close to a straight line, so the slope is its cost per cell.
Cost per cell, width 1 to 20: hand-written selector 1.91 ns, RowMap plan 3.65 ns, row class plus Select 4.12 ns, object[] dump 8.90 ns, Dapper 9.70 ns.
A reused map against a fresh one
Every number above uses a map that ODX builds once and caches. Building and compiling a map costs this much, once per map and result shape (one row per call):
| Columns | Reused map | Built every call | One-time cost |
|---|
On real databases
The same mapping paths on SQL Server LocalDB (SqlClient) and on a SQLite file, at 20 columns and 10,000 rows. A real provider spends its own time on every row, so mapping gaps that look large on the synthetic reader shrink to a few percent. Memory differences do not shrink.
On SQL Server the RowMap plan, the hand-written selector and the leanest hand loop are within 3% of each other, which is within run-to-run noise, while Dapper is 6% slower and allocates 29% more. On SQLite, which costs less per row, the plan is 21% slower than hand-written code and allocates 18% more. One run per cell; differences under about 5% cannot be told apart.
| Provider | Variant | 5 columns (ms) | 20 columns (ms) | 5 columns (MB) | 20 columns (MB) |
|---|
Sync reads against async reads
The same RowMap plan, read three ways, at 20 columns and 1,000 rows. Each panel is one condition: a buffer refill every 100 rows (20 µs each), a thread pool kept busy (8 work items), both, or neither. Shorter bars hold the connection for less time.
ExecuteReader, then Read()Async execute: ExecuteReaderAsync, then Read() (the default)Async read: ReadAsync() for every row (AsyncReads())Each panel has its own scale; compare bars within a panel. With a refill and a busy pool, every refill makes ReadAsync() wait about 1.2 ms for a free thread while the reader stays open: 11.2 ms against 0.28 ms for sync, 40 times longer (51 times at 5 columns). Sync and async execute do not move. Allocations are the same for all three (233 KB; async read adds 2.5 KB with refills). At one row no refill is reached and the three differ by under 0.1 µs.
This shows the mechanism in the synthetic model. A first probe on real providers (10,000 rows each) found that ReadAsync() almost never waits on local connections: 0 to 4 asynchronous completions in 10,000 reads on SQL Server LocalDB, including 8 KB rows, and none on a SQLite file. SQL Server 2022 over TCP (in Docker, on the same machine) behaved the same: 0 to 4 in 10,000, and the three paths were within the run's noise of each other. Without real network delay the rows arrive before ReadAsync() asks for them, so these setups cannot show the effect either way.
Over a shaped link (SQL Server in Docker, 5 ms delay, 100 Mbit), the link sets the total and every path takes the same time, with or without a busy pool (within 3 ms). Where the wait happens depends on the access mode. In SqlClient’s default mode, ReadAsync() reads the whole row and truly waits without blocking: 7.8% of calls for rows of 20 small columns, about 98% for 8 KB rows. With SequentialAccess, which ODX’s Map<T>() uses today, ReadAsync() returns early and the synchronous column reads wait on the network instead, blocking the thread. Async reads also allocate more: 16.6 MB against 9.7 MB for sync over the small rows, and about 3 times as much for the 8 KB rows.
Every number in a table
| Variant | Approach | Reader open (µs) | Total (µs) | Allocated (KB) | vs Dapper |
|---|