Skip to content

Commit f4ecdfe

Browse files
Make the two allocation tests deterministic: read their rows from the existing TypedReader (#136)
* Read the allocation tests' rows from arrays, so the fixture no longer boxes an int per row The two allocation tests compared bytes measured back to back through a DataTableReader, whose GetInt32 boxes each value (24 B per row). Tiered JIT removes that box part way through a measurement, so one side of a comparison could be 24 B per row cheaper than the other and the test failed at random. An ArrayReader serves typed getters straight from int[]/long[]/string[], so the measured bytes are the library's own at every tier. The thresholds, the warm-up and the tests' claims are unchanged. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * Use the existing TypedReader for the allocation tests' rows and drop ArrayReader TypedReader already serves typed getters over cells boxed once when the rows are built, so a row read allocates nothing; ArrayReader duplicated it. Ints and Rows now build a TypedReader. Thresholds and assertions are unchanged. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 566f17f commit f4ecdfe

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

‎Tests/Open.Database.Extensions.Core.Tests/MappedQuerySelectTests.cs‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -974,10 +974,12 @@ public static async Task AQueryFactory_LetsEachCallerPickTheTerminal()
974974

975975
static PlainReaderCommand Ints(int count)
976976
{
977-
DataTable table = new();
978-
table.Columns.Add("v", typeof(int));
979-
for (int i = 0; i < count; i++) table.Rows.Add(i);
980-
return new PlainReaderCommand(() => new DataTableReader(table));
977+
// A TypedReader serves cells boxed once, here, outside the measurement
978+
// (a DataTableReader boxes each int again on every read,
979+
// and the JIT removes that box part way through a measurement).
980+
ImmutableArray<ColumnDef> columns = [("v", typeof(int))];
981+
object?[][] rows = [.. Enumerable.Range(0, count).Select(i => (object?[])[i])];
982+
return new PlainReaderCommand(() => TypedReader.Create(columns, rows));
981983
}
982984

983985
// Bytes per call: after a warm-up,

‎Tests/Open.Database.Extensions.Core.Tests/SingleValueAllocationTests.cs‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,20 @@ static long BytesPerCall(Action call)
3636
// the two differ by no more than a rounding of the measurement.
3737
const int Slack = 16;
3838

39-
// A DataTableReader is a DbDataReader that reports its column type
39+
// A TypedReader is a DbDataReader that reports its column type
4040
// and has typed getters,
4141
// so the typed (unboxed) path runs.
42+
// Its cells are boxed once, here, outside the measurement
43+
// (a DataTableReader boxes every int it serves,
44+
// and the JIT removes that box part way through a measurement).
4245
static PlainReaderCommand Rows(
4346
Type column,
4447
int count,
4548
Func<int, object> value)
4649
{
47-
var table = new DataTable();
48-
table.Columns.Add("v", column);
49-
table.Columns.Add("other", typeof(string));
50-
for (int i = 0; i < count; i++) table.Rows.Add(value(i), "x");
51-
return new PlainReaderCommand(() => new DataTableReader(table));
50+
ImmutableArray<ColumnDef> columns = [("v", column), ("other", typeof(string))];
51+
object?[][] rows = [.. Enumerable.Range(0, count).Select(i => (object?[])[value(i), "x"])];
52+
return new PlainReaderCommand(() => TypedReader.Create(columns, rows));
5253
}
5354

5455
static void NoMoreThanByHand(

0 commit comments

Comments
 (0)