diff --git a/Benchmarks/Open.Database.Extensions.Benchmarks.Generated/GeneratedControl.cs b/Benchmarks/Open.Database.Extensions.Benchmarks.Generated/GeneratedControl.cs index 06ed9f73..d4ea9d81 100644 --- a/Benchmarks/Open.Database.Extensions.Benchmarks.Generated/GeneratedControl.cs +++ b/Benchmarks/Open.Database.Extensions.Benchmarks.Generated/GeneratedControl.cs @@ -154,4 +154,53 @@ public static object ControlT10(IExecuteReader command) public static object ControlHookedT10(IExecuteReader command) => command.Map(HookedT10).ToList(); + + // The A/A control (CtlH_T2): CtlH_T's readers again, textually the same, compiled as methods of their own. + static readonly Func ReadT20DbCopy = static r => new() + { + Id = r.GetInt32(0), + Created = r.GetDateTime(1), + Title = r.GetString(2), + Price = r.GetDecimal(3), + Qty = r.IsDBNull(4) ? null : r.GetInt32(4), + IsActive = r.GetBoolean(5), + Key = r.GetGuid(6), + Score = r.GetDouble(7), + Note = r.IsDBNull(8) ? null : r.GetString(8), + Blob = (byte[])r.GetValue(9), + Big = r.GetInt64(10), + Body = r.GetString(11), + Amount = r.IsDBNull(12) ? null : r.GetDecimal(12), + Stamp = r.IsDBNull(13) ? null : r.GetDateTime(13), + Tag = r.GetString(14), + Ratio = r.GetDouble(15), + Flag = r.IsDBNull(16) ? null : r.GetBoolean(16), + Link = r.IsDBNull(17) ? null : r.GetGuid(17), + Count = r.GetInt64(18), + Summary = r.IsDBNull(19) ? null : r.GetString(19), + }; + + static readonly RowMap HookedCopyT20 = Generation.GeneratedRowMap.Create(static _ => ReadT20DbCopy); + + public static object ControlHookedCopyT20(IExecuteReader command) + => command.Map(HookedCopyT20).ToList(); + + static readonly Func ReadT10DbCopy = static r => new() + { + Id = r.GetInt32(0), + Created = r.GetDateTime(1), + Title = r.GetString(2), + Price = r.GetDecimal(3), + Qty = r.IsDBNull(4) ? null : r.GetInt32(4), + IsActive = r.GetBoolean(5), + Key = r.GetGuid(6), + Score = r.GetDouble(7), + Note = r.IsDBNull(8) ? null : r.GetString(8), + Blob = (byte[])r.GetValue(9), + }; + + static readonly RowMap HookedCopyT10 = Generation.GeneratedRowMap.Create(static _ => ReadT10DbCopy); + + public static object ControlHookedCopyT10(IExecuteReader command) + => command.Map(HookedCopyT10).ToList(); } diff --git a/Benchmarks/Open.Database.Extensions.Benchmarks/GateBenchmarks.cs b/Benchmarks/Open.Database.Extensions.Benchmarks/GateBenchmarks.cs new file mode 100644 index 00000000..4f508e9e --- /dev/null +++ b/Benchmarks/Open.Database.Extensions.Benchmarks/GateBenchmarks.cs @@ -0,0 +1,410 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Columns; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Environments; +using BenchmarkDotNet.Jobs; +using BenchmarkDotNet.Order; +using BenchmarkDotNet.Running; +using BenchmarkDotNet.Toolchains.CsProj; +using BenchmarkDotNet.Toolchains.DotNetCli; +using Open.Database.Extensions.Benchmarks.Generated; +using Open.Database.Extensions.Synchronous; +using System.Collections; +using System.Collections.Immutable; +using System.Data; +using System.Data.Common; + +namespace Open.Database.Extensions.Benchmarks; + +// The gate: one table per read mode, and every row of a table reads in that mode. The synthetic reader and the real databases, widths 10 +// and 20, 1, 1,000 and 10,000 rows. The hand-written, selector and unannotated rungs build GenRowT10/20; GenD_T builds its annotated twin +// GenRowDT10/20 (the same members). +// +// CtlH_T baseline: the hand-written reader, same entry as the generated one +// CtlH_T2 A/A control: a separately compiled copy of CtlH_T. Its difference from the baseline is the noise and bias floor of the +// harness, so a GenD_T result means something only inside it; an A/A verdict other than Same means the harness is broken. +// GenD_T the generated reader of the annotated model +// Gen_T the generated reader of the unannotated model +// Selector the selector a caller writes, Map(selector) +// Dapper.AOT and Dapper: in both tables; unforced in the sequential one (their own mode), forced in the default one and labelled so. +// +// Every rung, forced or not, reads through ReadModeConnection (benchmarks only; library defaults are unchanged), so no rung pays a layer +// another does not, and setup checks the mode its rung read in. No gate table holds a cross-mode ratio; what the mode itself costs is +// ReadModeEffectBenchmarks, path by path. +// Over the synthetic reader the mode effect is that of the synthetic reader's own order check, not of a database; Microsoft.Data.Sqlite may +// ignore SequentialAccess, and then its two modes measure one thing twice. +// +// Every case runs in processes of its own (out of process), launched three times, the shapes and the rungs within each shuffled, with a +// verdict against the baseline (Mann-Whitney, 2% threshold). A process sets up and runs only its own rung (the oracle is plain ADO.NET), +// because a process that has run other shapes or rungs optimises the shared read loop for them. Never run these in process. +// A "Same" verdict is not proof of equivalence: read it with the A/A rung's spread. +// ODX_GATE_SOURCES synthetic,sqlite,sqlserver (default all; the databases also need ODX_RP_SCRATCH) +// ODX_GATE_WIDTHS to narrow: 10,20 (default both) +// ODX_GATE_ROWS to narrow: 1,1000,10000 (default all) +// ODX_GATE_ORDER the seed of the shuffled order (default: a new one, printed) +// ODX_GATE_SMOKE 1: a short run that only shows that every case runs in processes of its own. Its numbers mean nothing. +// Before a timed run: -- --verify-gate in a -p:OdxGeneratorCounters=true build. + +/// Not a benchmark (--verify-gate): runs every rung of every gate case once and checks it, before anything is timed. +/// In a build with -p:OdxGeneratorCounters=true the checks also prove that every generated rung is served by generated code. +public static class GateChecks +{ + public static int Verify() + { + int cases = 0; + foreach (string source in GateShapes.SourceValues) + { + foreach (int width in GateShapes.WidthValues) + { + foreach (int rows in GateShapes.RowValues) + { + Run(new GateDefaultAccessBenchmarks()); + Run(new GateSequentialAccessBenchmarks()); + Run(new ReadModeEffectBenchmarks { Generated = false }); + Run(new ReadModeEffectBenchmarks { Generated = true }); + + void Run(GateShapes gate) + { + gate.Source = source; + gate.Width = width; + gate.Rows = rows; + gate.VerifyAll(); + gate.Cleanup(); + cases++; + } + } + } + } + + Console.WriteLine($"// GATE-VERIFY {cases} cases: every rung read the right rows in its table's mode."); + return 0; + } +} + +/// Out of process on .NET 11, three launches, shuffled, with the median and the verdict against the baseline. +public sealed class GateConfig : ManualConfig +{ + public GateConfig() + { + bool smoke = Environment.GetEnvironmentVariable("ODX_GATE_SMOKE") == "1"; + Add(DefaultConfig.Instance); + // BenchmarkDotNet 0.15.8 does not know .NET 11 and refuses an unknown runtime: the job names .NET 10 for its checks while the + // toolchain builds and runs net11.0. Each process prints the runtime it is really on (GATE-PID). + AddJob(Job.Default + .WithRuntime(CoreRuntime.Core10_0) + .WithToolchain(CsProjCoreToolchain.From(new NetCoreAppSettings("net11.0", null, ".NET 11.0"))) + .WithLaunchCount(smoke ? 2 : 3) + .WithWarmupCount(smoke ? 1 : 5) + .WithIterationCount(smoke ? 3 : 12)); + AddColumn(StatisticColumn.Median); + AddColumn(StatisticalTestColumn.Create("2%", null)); + Orderer = new ShuffledOrderer(); + } +} + +/// +/// Shuffles the shapes, then the rungs within each shape (seed ODX_GATE_ORDER, else a new one, printed once): no rung always runs first, +/// and a rung runs close to the baseline it is compared with, so drift over a long run stays out of their ratio. +/// +public sealed class ShuffledOrderer : DefaultOrderer +{ + static readonly int Seed = Choose(); + + static int Choose() + { + int seed = int.TryParse(Environment.GetEnvironmentVariable("ODX_GATE_ORDER"), out int given) ? given : Random.Shared.Next(); + Console.WriteLine($"// GATE-ORDER seed {seed}"); + return seed; + } + + public override IEnumerable GetExecutionOrder(ImmutableArray benchmarksCase, IEnumerable? order = null) + { + var random = new Random(Seed); + return + [ + .. benchmarksCase + .GroupBy(static c => (c.Descriptor.Type, c.Parameters.DisplayInfo)) + .OrderBy(_ => random.Next()) + .SelectMany(shape => shape.OrderBy(_ => random.Next())), + ]; + } +} + +/// The case every gate table shares: where the rows come from, how wide and how many. +public abstract class GateShapes +{ + public const string Synthetic = "Synthetic"; + + [ParamsSource(nameof(SourceValues), Priority = 0)] + public string Source { get; set; } = ""; + + [ParamsSource(nameof(WidthValues), Priority = 1)] + public int Width { get; set; } + + [ParamsSource(nameof(RowValues), Priority = 2)] + public int Rows { get; set; } + + public static IEnumerable WidthValues => SyntheticParams.Parse(Environment.GetEnvironmentVariable("ODX_GATE_WIDTHS"), [10, 20]); + + public static IEnumerable RowValues => SyntheticParams.Parse(Environment.GetEnvironmentVariable("ODX_GATE_ROWS"), [1, 1000, 10_000]); + + public static IEnumerable SourceValues + => (Environment.GetEnvironmentVariable("ODX_GATE_SOURCES") is { Length: > 0 } list ? list : "synthetic,sqlite,sqlserver") + .Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries) + .Select(static s => s.Equals(Synthetic, StringComparison.OrdinalIgnoreCase) ? Synthetic : RealProviderParams.ParseProviders(s)[0]); + + RealProviderCase? _case; + DbConnection _connection = null!; + List _expected = null!; + + protected void Open() + { + if (Source == Synthetic) + { + _connection = new SyntheticConnection(SyntheticTable.Create(Width, Rows), new SyntheticOptions()); + RealProviderVariants.PrepareDapper(RealProviderParams.SqlServer); // No type handlers. + } + else + { + _case = RealProviderCase.Create(Source, Width, Rows); + _connection = _case.Real; + RealProviderVariants.PrepareDapper(Source); + } + + // The oracle, read with plain ADO.NET: a process times one rung, and no other reading may go through the library's shared read loop first. + _expected = Oracle(); + if (_expected.Count != Rows) throw new InvalidOperationException($"{_expected.Count} rows, expected {Rows}."); + GeneratedServesUnannotated = Source != RealProviderParams.Sqlite; + + // One line per process in the log: which case it ran. + Console.WriteLine($"// GATE-PID {Environment.ProcessId} {System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription} {GetType().Name} {Source} width={Width} rows={Rows}"); + } + + List Oracle() + { + Func hand = SyntheticVariants.Hand(Width); + using DbCommand command = _connection.CreateCommand(); + command.CommandText = RealProviderVariants.Sql; + using DbDataReader reader = command.ExecuteReader(); + var rows = new List(); + while (reader.Read()) rows.Add(hand(reader)); + return rows; + } + + /// Runs every rung of the case once and checks it (--verify-gate; a timed process checks only its own rung). + public abstract void VerifyAll(); + + /// The case's connection in the given read mode; leaves each reader as its caller asks. + protected ReadModeConnection In(bool? sequential) => new(_connection, sequential); + + // No case is timed over wrong rows or in another read mode than its table's; in a counters build a generated rung must be served by generated code. + protected void Check(string rung, ReadModeConnection connection, bool sequential, Func read, bool generated = false) + { + connection.Reset(); + IList rows = generated ? RealParityBenchmarks.Generated(rung, read) : (IList)read(); + if (connection.Last is not { } used || used.HasFlag(CommandBehavior.SequentialAccess) != sequential) + throw new InvalidOperationException($"{rung} read with {connection.Last}, not in its table's mode."); + RealParityBenchmarks.Same(rung, _expected, rows); + } + + [GlobalCleanup] + public void Cleanup() => _case?.Cleanup(); + + // SQLite stores a Guid as text, which the generated reader of an undecorated model leaves to the runtime map. + protected bool GeneratedServesUnannotated { get; private set; } + + static ExpressiveDbCommand Command(ReadModeConnection connection) => connection.Command(RealProviderVariants.Sql); + + protected object Hand(ReadModeConnection c) + => Width == 10 ? GeneratedControl.ControlHookedT10(Command(c)) : GeneratedControl.ControlHookedT20(Command(c)); + + protected object HandCopy(ReadModeConnection c) + => Width == 10 ? GeneratedControl.ControlHookedCopyT10(Command(c)) : GeneratedControl.ControlHookedCopyT20(Command(c)); + + protected object Annotated(ReadModeConnection c) + => Width == 10 ? GeneratedReads.GenDT10(Command(c)) : GeneratedReads.GenDT20(Command(c)); + + protected object Unannotated(ReadModeConnection c) + { + if (!GeneratedServesUnannotated) throw new NotSupportedException("Gen_T is not served by generated code on SQLite."); + return Width == 10 ? GeneratedReads.GenT10(Command(c)) : GeneratedReads.GenT20(Command(c)); + } + + protected object Written(ReadModeConnection c) + => Width == 10 ? GeneratedControl.ControlT10(Command(c)) : GeneratedControl.ControlT20(Command(c)); +} + +/// The rungs of a gate table, all reading in the table's mode. Each timed process sets up and checks only its own rung. +public abstract class GateRungs : GateShapes +{ + ReadModeConnection _mode = null!; + + /// The table's read mode. + protected abstract bool Sequential { get; } + + protected void Prepare() + { + Open(); + _mode = In(Sequential); + } + + // One rung's checks, after Prepare. + protected void CheckRung(string rung, Func read, bool generated = false) + => Check(rung, _mode, Sequential, read, generated); + + public override void VerifyAll() + { + Prepare(); + CheckRung(nameof(CtlH_T), CtlH_T); + CheckRung(nameof(CtlH_T2), CtlH_T2); + CheckRung(nameof(GenD_T), GenD_T, generated: true); + if (GeneratedServesUnannotated) CheckRung(nameof(Gen_T), Gen_T, generated: true); + CheckRung(nameof(Selector), Selector); + } + + [GlobalSetup(Target = nameof(CtlH_T))] + public void SetupCtlH_T() { Prepare(); CheckRung(nameof(CtlH_T), CtlH_T); } + + [GlobalSetup(Target = nameof(CtlH_T2))] + public void SetupCtlH_T2() { Prepare(); CheckRung(nameof(CtlH_T2), CtlH_T2); } + + [GlobalSetup(Target = nameof(GenD_T))] + public void SetupGenD_T() { Prepare(); CheckRung(nameof(GenD_T), GenD_T, generated: true); } + + [GlobalSetup(Target = nameof(Gen_T))] + public void SetupGen_T() + { + Prepare(); + if (GeneratedServesUnannotated) CheckRung(nameof(Gen_T), Gen_T, generated: true); + } + + [GlobalSetup(Target = nameof(Selector))] + public void SetupSelector() { Prepare(); CheckRung(nameof(Selector), Selector); } + + [Benchmark(Baseline = true)] + public object CtlH_T() => Hand(_mode); + + [Benchmark] + public object CtlH_T2() => HandCopy(_mode); + + [Benchmark] + public object GenD_T() => Annotated(_mode); + + [Benchmark] + public object Gen_T() => Unannotated(_mode); + + [Benchmark] + public object Selector() => Written(_mode); + + protected object ReadDapperAot(ReadModeConnection c) => Width == 10 ? RealProviderDapperAot.V7aT10(c) : RealProviderDapperAot.V7aT(c); + + protected object ReadDapper(ReadModeConnection c) => RealProviderVariants.V7T(c, Width); +} + +/// The gate table of default access. Dapper.AOT and Dapper are forced into it: their own mode is sequential. +[MemoryDiagnoser] +[Config(typeof(GateConfig))] +public class GateDefaultAccessBenchmarks : GateRungs +{ + ReadModeConnection _forced = null!; + + protected override bool Sequential => false; + + void Force() + { + Prepare(); + _forced = In(false); + } + + public override void VerifyAll() + { + base.VerifyAll(); + _forced = In(false); + Check(nameof(DapperAot), _forced, sequential: false, DapperAot); + Check(nameof(Dapper), _forced, sequential: false, Dapper); + } + + [GlobalSetup(Target = nameof(DapperAot))] + public void SetupDapperAot() { Force(); Check(nameof(DapperAot), _forced, sequential: false, DapperAot); } + + [GlobalSetup(Target = nameof(Dapper))] + public void SetupDapper() { Force(); Check(nameof(Dapper), _forced, sequential: false, Dapper); } + + [Benchmark(Description = "Dapper.AOT (forced)")] + public object DapperAot() => ReadDapperAot(_forced); + + [Benchmark(Description = "Dapper (forced)")] + public object Dapper() => ReadDapper(_forced); +} + +/// The gate table of sequential access. Dapper.AOT and Dapper use it themselves: nothing is forced on them. +[MemoryDiagnoser] +[Config(typeof(GateConfig))] +public class GateSequentialAccessBenchmarks : GateRungs +{ + ReadModeConnection _own = null!; + + protected override bool Sequential => true; + + void Unforced() + { + Prepare(); + _own = In(null); + } + + public override void VerifyAll() + { + base.VerifyAll(); + _own = In(null); + Check(nameof(DapperAot), _own, sequential: true, DapperAot); + Check(nameof(Dapper), _own, sequential: true, Dapper); + } + + [GlobalSetup(Target = nameof(DapperAot))] + public void SetupDapperAot() { Unforced(); Check(nameof(DapperAot), _own, sequential: true, DapperAot); } + + [GlobalSetup(Target = nameof(Dapper))] + public void SetupDapper() { Unforced(); Check(nameof(Dapper), _own, sequential: true, Dapper); } + + [Benchmark(Description = "Dapper.AOT")] + public object DapperAot() => ReadDapperAot(_own); + + [Benchmark] + public object Dapper() => ReadDapper(_own); +} + +/// What the read mode itself costs, path by path: default access against sequential, the same reader code. +[MemoryDiagnoser] +[Config(typeof(GateConfig))] +public class ReadModeEffectBenchmarks : GateShapes +{ + ReadModeConnection _sequential = null!, _default = null!; + + [Params(false, true)] + public bool Generated { get; set; } + + void Prepare() + { + Open(); + _sequential = In(true); + _default = In(false); + } + + public override void VerifyAll() + { + SetupSequential(); + Check(nameof(DefaultAccess), _default, sequential: false, DefaultAccess, Generated); + } + + [GlobalSetup(Target = nameof(Sequential))] + public void SetupSequential() { Prepare(); Check(nameof(Sequential), _sequential, sequential: true, Sequential, Generated); } + + [GlobalSetup(Target = nameof(DefaultAccess))] + public void SetupDefaultAccess() { Prepare(); Check(nameof(DefaultAccess), _default, sequential: false, DefaultAccess, Generated); } + + [Benchmark(Baseline = true)] + public object Sequential() => Generated ? Annotated(_sequential) : Hand(_sequential); + + [Benchmark] + public object DefaultAccess() => Generated ? Annotated(_default) : Hand(_default); +} diff --git a/Benchmarks/Open.Database.Extensions.Benchmarks/GenParity.cs b/Benchmarks/Open.Database.Extensions.Benchmarks/GenParity.cs index 3741f447..dfb0e6ae 100644 --- a/Benchmarks/Open.Database.Extensions.Benchmarks/GenParity.cs +++ b/Benchmarks/Open.Database.Extensions.Benchmarks/GenParity.cs @@ -30,10 +30,9 @@ namespace Open.Database.Extensions.Benchmarks; // reader's per-binding counter gives. Nothing here checks the reported index. // GP7 the raw loop (as V10r): ExecuteReader's callback, while (db.Read()) list.Add(Read(db)), V2's read at constant ordinals on DbDataReader, // with ONE try/catch around the whole loop (the row number a loop local): the placement the generator now gets from Core's loop through -// the GeneratedRowMap hook. GP7 and GP7c open the reader with CommandBehavior.SequentialAccess -// (as V10r does), where V2 and every Map(Func) selector run with the default behavior: so GP7 against V2 or GP6 changes the access mode as well as -// the loop placement. Only GP7 against GP7c isolates the try. -// GP7c GP7 with no try: the bar of the loop placement (SequentialAccess too). +// the GeneratedRowMap hook. GP7 and GP7c open the reader with the default behavior (as V10r, V2 and every +// library read do), so GP7 against V2 or GP6 changes only the loop placement. GP7 against GP7c isolates the try. +// GP7c GP7 with no try: the bar of the loop placement. // // WIDTH 20 ONLY. V2n, GP2 to GP7c and (SyntheticBenchmarks.cs) Ctl read the 20 catalog columns at fixed ordinals. At widths 1, 3, 5 and 10 // the provider has fewer columns, so each of these methods throws NotSupportedException from its own width check, and BenchmarkDotNet reports the case as @@ -282,7 +281,7 @@ public static List GP7(DbConnection connection) while (db.NextResult()) { } return list; - }, CommandBehavior.SequentialAccess); + }, CommandBehavior.Default); /// GP7c: the raw loop of GP7 with no try. public static List GP7c(DbConnection connection) @@ -293,7 +292,7 @@ public static List GP7c(DbConnection connection) while (db.Read()) list.Add(Read7(db)); while (db.NextResult()) { } return list; - }, CommandBehavior.SequentialAccess); + }, CommandBehavior.Default); // V2's read on DbDataReader (the loop's static type, as V10r's row method takes it). static SynRow Read7(DbDataReader r) => new() diff --git a/Benchmarks/Open.Database.Extensions.Benchmarks/GeneratorShaped.cs b/Benchmarks/Open.Database.Extensions.Benchmarks/GeneratorShaped.cs index 212268cf..ad4a3eef 100644 --- a/Benchmarks/Open.Database.Extensions.Benchmarks/GeneratorShaped.cs +++ b/Benchmarks/Open.Database.Extensions.Benchmarks/GeneratorShaped.cs @@ -24,9 +24,9 @@ namespace Open.Database.Extensions.Benchmarks; // IRowSource, the interface that would take a generated mapper without a delegate, is INTERNAL, and RowMap has no public way to hand it one). // So V10 is NOT delegate-free: one delegate call per row and the selector's reader field. The selector is an object made per query, resolves the // ordinals on its first row (one result set: the first one, the only one Map reads) and then calls the same typed row method on the reader the -// loop hands it (a DbDataReader, cast once). It runs with the access mode the library picks for a selector (default, not SequentialAccess). +// loop hands it (a DbDataReader, cast once). It runs with the library's access mode (default). // V10r the RAW LOOP: ExecuteReader's callback, while (reader.Read()) list.Add(Read(reader, in ordinals)), the later result sets read through as every hand -// variant does (V9c's loop and drain), SequentialAccess. No delegate and no interface call per cell or per row. Static type DbDataReader. +// variant does (V9c's loop and drain), default access. No delegate and no interface call per cell or per row. Static type DbDataReader. // V10c V10r on the sealed SyntheticReader (synthetic provider only): the gap to V10r is what a concrete reader is worth over a virtual call. // V10i V10 with the row method marked AggressiveInlining, called exactly as V10 calls it (through the selector delegate); the JIT cannot inline through a delegate except by guarded devirtualization under dynamic PGO, so what it did is the measurement. // V10ri V10r with the AggressiveInlining row method called DIRECTLY (no delegate); V10rn the same with a NoInlining row method ("called, not inlined", stated and not left to the JIT). @@ -34,8 +34,8 @@ namespace Open.Database.Extensions.Benchmarks; // so the only differences between V10rn, V10ri and V10L are the call (made / inlined by the attribute / fused); the one remaining difference is that ReadAll's struct is a local and the row methods get it as an `in` reference. // V10r on the real providers is written on the CONCRETE reader (SqlDataReader, SqliteDataReader) as V9c is, and takes its own stopwatch like V9c. // -// SequentialAccess reads columns in ascending ordinal order only. The row method reads in property order, so V10r and V10c are right only while the -// ordinals ascend (true for every table here). A generator would have to read in column order (a switch per column) or use the default access mode. +// The row method reads in property order, which is column order for every table here (see Ascend), as a reader opened with SequentialAccess() +// would need. /// The ordinal of each property in a result set (-1: no column feeds it). public readonly struct SynRowOrdinals @@ -256,7 +256,7 @@ public static List V10L(DbConnection connection, string sql) var list = SynRowGenerated.ReadAll(db); while (db.NextResult()) { } return list; - }, CommandBehavior.SequentialAccess); + }, CommandBehavior.Default); /// V10r: the raw loop, static type DbDataReader. public static List V10r(DbConnection connection, string sql) @@ -268,7 +268,7 @@ public static List V10r(DbConnection connection, string sql) while (db.Read()) list.Add(SynRowGenerated.Read(db, in ordinals)); while (db.NextResult()) { } return list; - }, CommandBehavior.SequentialAccess); + }, CommandBehavior.Default); /// V10c: the raw loop on the sealed SyntheticReader. public static List V10c(DbConnection connection, string sql) @@ -280,7 +280,7 @@ public static List V10c(DbConnection connection, string sql) while (db.Read()) list.Add(SynRowGenerated.Read(db, in ordinals)); while (db.NextResult()) { } return list; - }, CommandBehavior.SequentialAccess); + }, CommandBehavior.Default); /// V10r on SQL Server: the concrete reader, its own stopwatch (as V9c: the reader is the provider's, not the timing wrapper's). public static List V10rSql(SqlConnection connection, SyntheticRecorder recorder) @@ -289,7 +289,7 @@ public static List V10rSql(SqlConnection connection, SyntheticRecorder r command.CommandText = RealProviderVariants.Sql; var list = new List(); long start = Stopwatch.GetTimestamp(); - using (var reader = command.ExecuteReader(CommandBehavior.SequentialAccess)) + using (var reader = command.ExecuteReader(CommandBehavior.Default)) { var ordinals = SynRowGenerated.Resolve(reader); while (reader.Read()) list.Add(SynRowGenerated.Read(reader, in ordinals)); @@ -307,7 +307,7 @@ public static List V10LSql(SqlConnection connection, SyntheticRecorder r command.CommandText = RealProviderVariants.Sql; List list; long start = Stopwatch.GetTimestamp(); - using (var reader = command.ExecuteReader(CommandBehavior.SequentialAccess)) + using (var reader = command.ExecuteReader(CommandBehavior.Default)) { list = SynRowGenerated.ReadAll(reader); while (reader.NextResult()) { } @@ -324,7 +324,7 @@ public static List V10LLite(SqliteConnection connection, SyntheticRecord command.CommandText = RealProviderVariants.Sql; List list; long start = Stopwatch.GetTimestamp(); - using (var reader = command.ExecuteReader(CommandBehavior.SequentialAccess)) + using (var reader = command.ExecuteReader(CommandBehavior.Default)) { list = SynRowGenerated.ReadAll(reader); while (reader.NextResult()) { } @@ -341,7 +341,7 @@ public static List V10rLite(SqliteConnection connection, SyntheticRecord command.CommandText = RealProviderVariants.Sql; var list = new List(); long start = Stopwatch.GetTimestamp(); - using (var reader = command.ExecuteReader(CommandBehavior.SequentialAccess)) + using (var reader = command.ExecuteReader(CommandBehavior.Default)) { var ordinals = SynRowGenerated.Resolve(reader); while (reader.Read()) list.Add(SynRowGenerated.Read(reader, in ordinals)); @@ -362,7 +362,7 @@ public static List V10ri(DbConnection connection, string sql) while (db.Read()) list.Add(SynRowGenerated.ReadInline(db, in ordinals)); while (db.NextResult()) { } return list; - }, CommandBehavior.SequentialAccess); + }, CommandBehavior.Default); /// V10ri on SQL Server: the concrete reader, its own stopwatch. public static List V10riSql(SqlConnection connection, SyntheticRecorder recorder) @@ -371,7 +371,7 @@ public static List V10riSql(SqlConnection connection, SyntheticRecorder command.CommandText = RealProviderVariants.Sql; var list = new List(); long start = Stopwatch.GetTimestamp(); - using (var reader = command.ExecuteReader(CommandBehavior.SequentialAccess)) + using (var reader = command.ExecuteReader(CommandBehavior.Default)) { var ordinals = SynRowGenerated.Resolve(reader); while (reader.Read()) list.Add(SynRowGenerated.ReadInline(reader, in ordinals)); @@ -389,7 +389,7 @@ public static List V10riLite(SqliteConnection connection, SyntheticRecor command.CommandText = RealProviderVariants.Sql; var list = new List(); long start = Stopwatch.GetTimestamp(); - using (var reader = command.ExecuteReader(CommandBehavior.SequentialAccess)) + using (var reader = command.ExecuteReader(CommandBehavior.Default)) { var ordinals = SynRowGenerated.Resolve(reader); while (reader.Read()) list.Add(SynRowGenerated.ReadInline(reader, in ordinals)); @@ -410,7 +410,7 @@ public static List V10rn(DbConnection connection, string sql) while (db.Read()) list.Add(SynRowGenerated.ReadNoInline(db, in ordinals)); while (db.NextResult()) { } return list; - }, CommandBehavior.SequentialAccess); + }, CommandBehavior.Default); /// V10rn on SQL Server: the concrete reader, its own stopwatch. public static List V10rnSql(SqlConnection connection, SyntheticRecorder recorder) @@ -419,7 +419,7 @@ public static List V10rnSql(SqlConnection connection, SyntheticRecorder command.CommandText = RealProviderVariants.Sql; var list = new List(); long start = Stopwatch.GetTimestamp(); - using (var reader = command.ExecuteReader(CommandBehavior.SequentialAccess)) + using (var reader = command.ExecuteReader(CommandBehavior.Default)) { var ordinals = SynRowGenerated.Resolve(reader); while (reader.Read()) list.Add(SynRowGenerated.ReadNoInline(reader, in ordinals)); @@ -437,7 +437,7 @@ public static List V10rnLite(SqliteConnection connection, SyntheticRecor command.CommandText = RealProviderVariants.Sql; var list = new List(); long start = Stopwatch.GetTimestamp(); - using (var reader = command.ExecuteReader(CommandBehavior.SequentialAccess)) + using (var reader = command.ExecuteReader(CommandBehavior.Default)) { var ordinals = SynRowGenerated.Resolve(reader); while (reader.Read()) list.Add(SynRowGenerated.ReadNoInline(reader, in ordinals)); @@ -466,7 +466,7 @@ public static List V10k(DbConnection connection, string sql, int width) }; while (db.NextResult()) { } return list; - }, CommandBehavior.SequentialAccess); + }, CommandBehavior.Default); /// V10kri: required members, the raw loop calling an AggressiveInlining row method (the twin of V10ri). public static List V10kri(DbConnection connection, string sql, int width) @@ -484,7 +484,7 @@ public static List V10kri(DbConnection connection, string sql, int width }; while (db.NextResult()) { } return list; - }, CommandBehavior.SequentialAccess); + }, CommandBehavior.Default); /// V10kL: required members, the whole loop generated, the mapping inline in the loop (the twin of V10L). public static List V10kL(DbConnection connection, string sql, int width) @@ -502,5 +502,5 @@ public static List V10kL(DbConnection connection, string sql, int width) }; while (db.NextResult()) { } return list; - }, CommandBehavior.SequentialAccess); + }, CommandBehavior.Default); } diff --git a/Benchmarks/Open.Database.Extensions.Benchmarks/PooledBufferCostBenchmarks.cs b/Benchmarks/Open.Database.Extensions.Benchmarks/PooledBufferCostBenchmarks.cs index 41b30a6c..d0db1cad 100644 --- a/Benchmarks/Open.Database.Extensions.Benchmarks/PooledBufferCostBenchmarks.cs +++ b/Benchmarks/Open.Database.Extensions.Benchmarks/PooledBufferCostBenchmarks.cs @@ -214,7 +214,7 @@ async ValueTask NoBuffer(string label, Work work) while (reader.NextResult()) { } return total; }, - CommandBehavior.SequentialAccess) + CommandBehavior.Default) .ConfigureAwait(false); return VerifySum(sum); diff --git a/Benchmarks/Open.Database.Extensions.Benchmarks/Program.cs b/Benchmarks/Open.Database.Extensions.Benchmarks/Program.cs index 834ebd39..382bba7a 100644 --- a/Benchmarks/Open.Database.Extensions.Benchmarks/Program.cs +++ b/Benchmarks/Open.Database.Extensions.Benchmarks/Program.cs @@ -16,8 +16,9 @@ // -- --selftest-in6 the probe's timing wrappers and engine, against the synthetic provider (no database) // -- --selftest-s4 the large-value probe's cell runner, result line and checksum, on SQLite (--s4, --s4-setup, --s4-teardown: see S4Probe.cs) // -- --verify-rp --scratch [--sqlite-dir ] equal final objects from every real-provider variant (LocalDB and a SQLite file), see RealProviderBenchmarks.cs +// -- --verify-gate every gate case's rows and read modes (ODX_GATE_SOURCES, ODX_RP_SCRATCH), see GateBenchmarks.cs // The checks say which runtime and target framework they ran on (the build is multi-targeted). -if (args.Any(static a => a is "--verify" or "--selftest-open-time" or "--selftest-alloc" or "--selftest-pace" or "--selftest-refill" or "--selftest-in6" or "--verify-rp" or "--calibrate-spin" or "--in6") || S4Probe.Handles(args)) +if (args.Any(static a => a is "--verify" or "--selftest-open-time" or "--selftest-alloc" or "--selftest-pace" or "--selftest-refill" or "--selftest-in6" or "--verify-rp" or "--verify-gate" or "--calibrate-spin" or "--in6") || S4Probe.Handles(args)) { Console.WriteLine("runtime: " + System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription + ", built for: " + System.Reflection.Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(System.Runtime.Versioning.TargetFrameworkAttribute), false) @@ -36,6 +37,12 @@ return; } +if (args.Contains("--verify-gate")) +{ + Environment.ExitCode = GateChecks.Verify(); + return; +} + if (args.Contains("--selftest-open-time")) { Environment.ExitCode = SyntheticChecks.SelfTestOpenTime(); diff --git a/Benchmarks/Open.Database.Extensions.Benchmarks/ReadModeConnection.cs b/Benchmarks/Open.Database.Extensions.Benchmarks/ReadModeConnection.cs new file mode 100644 index 00000000..b6cac90b --- /dev/null +++ b/Benchmarks/Open.Database.Extensions.Benchmarks/ReadModeConnection.cs @@ -0,0 +1,72 @@ +using System.Data; +using System.Data.Common; +using System.Diagnostics.CodeAnalysis; + +namespace Open.Database.Extensions.Benchmarks; + +/// +/// Benchmarks only: opens every reader in a fixed read mode over an open connection, so one read path can be measured in either mode. +/// The provider's own reader is returned, so nothing is added per row, only one call per command. +/// +/// The open connection; the caller owns it. +/// adds , removes it, leaves what the caller asked for. +public sealed class ReadModeConnection(DbConnection inner, bool? sequential) : DbConnection +{ + /// The behaviour the last reader was opened with, or since . + public CommandBehavior? Last { get; private set; } + + public void Reset() => Last = null; + + public CommandBehavior Apply(CommandBehavior behavior) + { + CommandBehavior used = sequential switch + { + true => behavior | CommandBehavior.SequentialAccess, + false => behavior & ~CommandBehavior.SequentialAccess, + null => behavior, + }; + Last = used; + return used; + } + + [AllowNull] + public override string ConnectionString { get => inner.ConnectionString; set => inner.ConnectionString = value; } + public override string Database => inner.Database; + public override string DataSource => inner.DataSource; + public override string ServerVersion => inner.ServerVersion; + public override ConnectionState State => inner.State; + public override void ChangeDatabase(string databaseName) => inner.ChangeDatabase(databaseName); + public override void Close() => inner.Close(); + public override void Open() => inner.Open(); + protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel) => throw new NotSupportedException(); + protected override DbCommand CreateDbCommand() => new ReadModeCommand(inner.CreateCommand(), this); +} + +/// The command of a . +public sealed class ReadModeCommand(DbCommand inner, ReadModeConnection connection) : DbCommand +{ + [AllowNull] + public override string CommandText { get => inner.CommandText; set => inner.CommandText = value; } + public override int CommandTimeout { get => inner.CommandTimeout; set => inner.CommandTimeout = value; } + public override CommandType CommandType { get => inner.CommandType; set => inner.CommandType = value; } + public override bool DesignTimeVisible { get => inner.DesignTimeVisible; set => inner.DesignTimeVisible = value; } + public override UpdateRowSource UpdatedRowSource { get => inner.UpdatedRowSource; set => inner.UpdatedRowSource = value; } + protected override DbConnection? DbConnection { get => connection; set { } } + protected override DbParameterCollection DbParameterCollection => inner.Parameters; + protected override DbTransaction? DbTransaction { get => inner.Transaction; set => inner.Transaction = value; } + public override void Cancel() => inner.Cancel(); + public override int ExecuteNonQuery() => inner.ExecuteNonQuery(); + public override object? ExecuteScalar() => inner.ExecuteScalar(); + public override void Prepare() => inner.Prepare(); + protected override DbParameter CreateDbParameter() => inner.CreateParameter(); + protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior) => inner.ExecuteReader(connection.Apply(behavior)); + + protected override Task ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken) + => inner.ExecuteReaderAsync(connection.Apply(behavior), cancellationToken); + + protected override void Dispose(bool disposing) + { + if (disposing) inner.Dispose(); + base.Dispose(disposing); + } +} diff --git a/Benchmarks/Open.Database.Extensions.Benchmarks/RealParityBenchmarks.cs b/Benchmarks/Open.Database.Extensions.Benchmarks/RealParityBenchmarks.cs index 699f1f0b..4466ec2b 100644 --- a/Benchmarks/Open.Database.Extensions.Benchmarks/RealParityBenchmarks.cs +++ b/Benchmarks/Open.Database.Extensions.Benchmarks/RealParityBenchmarks.cs @@ -56,7 +56,7 @@ public void Setup() static long Count(string name) => (long)Counters!.GetField(name)!.GetValue(null)!; - static IList Generated(string method, Func read) + public static IList Generated(string method, Func read) { if (Counters is null) return (IList)read(); @@ -78,7 +78,7 @@ public void Cleanup() } // Every property of the row type against the same property of V2's row. - static void Same(string method, List expected, IList actual) + public static void Same(string method, List expected, IList actual) { if (actual.Count != expected.Count) throw new InvalidOperationException($"{method}: {actual.Count} rows, expected {expected.Count}."); diff --git a/Benchmarks/Open.Database.Extensions.Benchmarks/RealProviderPlainReadLoop.cs b/Benchmarks/Open.Database.Extensions.Benchmarks/RealProviderPlainReadLoop.cs index b98e3f6d..cee96fac 100644 --- a/Benchmarks/Open.Database.Extensions.Benchmarks/RealProviderPlainReadLoop.cs +++ b/Benchmarks/Open.Database.Extensions.Benchmarks/RealProviderPlainReadLoop.cs @@ -1,3 +1,4 @@ +using BenchmarkDotNet.Engines; using System.Data; using System.Data.Common; @@ -10,7 +11,9 @@ namespace Open.Database.Extensions.Benchmarks; /// /// /// Through the same connection the library and Dapper variants get (the timing wrapper), so its forwarding cost is in the loop as it is in them. -/// SequentialAccess, as the library's row-map reads and V9c open the reader. Widths 5 and 20, the columns of in order. +/// Default access, as the library's row-map reads and V9c open the reader. Widths 5 and 20, the columns of in order. +/// Every value read goes to : a getter the JIT inlines must still produce it, +/// or the loop would not do the reading it stands for. The call costs the loop a little per cell, which only raises the floor. /// public static class RealProviderPlainReadLoop { @@ -26,7 +29,7 @@ public static int Read(DbConnection connection, int width) using DbCommand command = connection.CreateCommand(); command.CommandText = RealProviderVariants.Sql; - using DbDataReader reader = command.ExecuteReader(CommandBehavior.SequentialAccess); + using DbDataReader reader = command.ExecuteReader(CommandBehavior.Default); int rows = 0; while (reader.Read()) { @@ -38,33 +41,34 @@ public static int Read(DbConnection connection, int width) return rows; } - // The values are dropped: a getter is a call into the provider, which cannot be removed. + static void Keep(T value) => DeadCodeEliminationHelper.KeepAliveWithoutBoxing(value); + static void Row5(DbDataReader r) { - _ = r.GetInt32(0); - _ = r.GetDateTime(1); - _ = r.GetString(2); - _ = r.GetDecimal(3); - if (!r.IsDBNull(4)) _ = r.GetInt32(4); + Keep(r.GetInt32(0)); + Keep(r.GetDateTime(1)); + Keep(r.GetString(2)); + Keep(r.GetDecimal(3)); + if (!r.IsDBNull(4)) Keep(r.GetInt32(4)); } static void Row20(DbDataReader r) { Row5(r); - _ = r.GetBoolean(5); - _ = r.GetGuid(6); - _ = r.GetDouble(7); - if (!r.IsDBNull(8)) _ = r.GetString(8); - _ = r.GetValue(9); - _ = r.GetInt64(10); - _ = r.GetString(11); - if (!r.IsDBNull(12)) _ = r.GetDecimal(12); - if (!r.IsDBNull(13)) _ = r.GetDateTime(13); - _ = r.GetString(14); - _ = r.GetDouble(15); - if (!r.IsDBNull(16)) _ = r.GetBoolean(16); - if (!r.IsDBNull(17)) _ = r.GetGuid(17); - _ = r.GetInt64(18); - if (!r.IsDBNull(19)) _ = r.GetString(19); + Keep(r.GetBoolean(5)); + Keep(r.GetGuid(6)); + Keep(r.GetDouble(7)); + if (!r.IsDBNull(8)) Keep(r.GetString(8)); + Keep(r.GetValue(9)); + Keep(r.GetInt64(10)); + Keep(r.GetString(11)); + if (!r.IsDBNull(12)) Keep(r.GetDecimal(12)); + if (!r.IsDBNull(13)) Keep(r.GetDateTime(13)); + Keep(r.GetString(14)); + Keep(r.GetDouble(15)); + if (!r.IsDBNull(16)) Keep(r.GetBoolean(16)); + if (!r.IsDBNull(17)) Keep(r.GetGuid(17)); + Keep(r.GetInt64(18)); + if (!r.IsDBNull(19)) Keep(r.GetString(19)); } } diff --git a/Benchmarks/Open.Database.Extensions.Benchmarks/RealProviderVariants.cs b/Benchmarks/Open.Database.Extensions.Benchmarks/RealProviderVariants.cs index 53f4202d..2e6a96d8 100644 --- a/Benchmarks/Open.Database.Extensions.Benchmarks/RealProviderVariants.cs +++ b/Benchmarks/Open.Database.Extensions.Benchmarks/RealProviderVariants.cs @@ -21,7 +21,7 @@ namespace Open.Database.Extensions.Benchmarks; // V7 Dapper 2.1.89 connection.Query(sql).AsList() // V7a the same call through Dapper.AOT 1.1.0's interceptor (RealProviderDapperAot.cs, the only class with [DapperAot]) // V9c the typed-getter ceiling: a hand loop with typed getters on the CONCRETE reader (SqlDataReader or SqliteDataReader), constant ordinals, -// IsDBNull only on the columns that can be NULL, SequentialAccess, the later result sets read through as the library does. Written once per +// IsDBNull only on the columns that can be NULL, default access, the later result sets read through as the library does. Written once per // provider and width (5 and 20) because BS-C's V9c is written against the synthetic reader only. // V9c-wrapped (control, not part of the matrix) the same loop on the timing wrapper's DbDataReader: what the wrapper's forwarding costs. // V_best the slot for the best BS-C candidate. EMPTY until the planning session names it: nothing is wired here and nothing is guessed. @@ -51,6 +51,12 @@ public static class RealProviderVariants public static List V7(DbConnection connection) => connection.Query(Sql).AsList(); + /// V7 building the generated rung's row type of the width (10 or 20). + public static object V7T(DbConnection connection, int width) + => width == 10 + ? connection.Query(Sql).AsList() + : connection.Query(Sql).AsList(); + /// /// Dapper reads a TEXT column into a Guid member only through a type handler (SQLite stores a Guid as text and Dapper does not convert it); this is the standard /// recipe for SQLite. registers it for SQLite cases and clears every handler for SQL Server cases, so a SQL Server run never pays for it. @@ -78,7 +84,7 @@ public static List V9cSql(SqlConnection connection, SyntheticRecorder re command.CommandText = Sql; var list = new List(); long start = Stopwatch.GetTimestamp(); - using (var reader = command.ExecuteReader(CommandBehavior.SequentialAccess)) + using (var reader = command.ExecuteReader(CommandBehavior.Default)) { while (reader.Read()) list.Add(read(reader)); @@ -96,7 +102,7 @@ public static List V9cLite(SqliteConnection connection, SyntheticRecorde command.CommandText = Sql; var list = new List(); long start = Stopwatch.GetTimestamp(); - using (var reader = command.ExecuteReader(CommandBehavior.SequentialAccess)) + using (var reader = command.ExecuteReader(CommandBehavior.Default)) { while (reader.Read()) list.Add(read(reader)); @@ -119,7 +125,7 @@ public static List V9cWrapped(DbConnection timed, Func SqlReader(int width) => width switch { diff --git a/Benchmarks/Open.Database.Extensions.Benchmarks/S4Cells.cs b/Benchmarks/Open.Database.Extensions.Benchmarks/S4Cells.cs index 39bdac81..bc7ff97f 100644 --- a/Benchmarks/Open.Database.Extensions.Benchmarks/S4Cells.cs +++ b/Benchmarks/Open.Database.Extensions.Benchmarks/S4Cells.cs @@ -15,8 +15,8 @@ namespace Open.Database.Extensions.Benchmarks; // R4 raw ADO.NET, CommandBehavior.SequentialAccess, await ReadAsync, sync getters // R5 raw ADO.NET, CommandBehavior.SequentialAccess, await ReadAsync, await GetFieldValueAsync for the large column (Id: the sync getter GetInt32) // O1 ODX EnableAsyncRead().Map(selector).ToListAsync() (Default + ReadAsync inside ODX) -// O2 ODX EnableAsyncRead().Map().ToListAsync() (SequentialAccess + ReadAsync inside ODX) -// O3 ODX Map().ToList() (SequentialAccess + sync Read) +// O2 ODX EnableAsyncRead().Map().ToListAsync() (Default + ReadAsync inside ODX) +// O3 ODX Map().ToList() (Default + sync Read) // The raw paths use the provider's own connection and command with no wrapper types; the ODX paths run behind the IN6 timing wrapper (wrapper=yes). /// A row with an Id and a binary large value. diff --git a/Benchmarks/Open.Database.Extensions.Benchmarks/SyntheticBenchmarks.cs b/Benchmarks/Open.Database.Extensions.Benchmarks/SyntheticBenchmarks.cs index a359c18b..01ac6c53 100644 --- a/Benchmarks/Open.Database.Extensions.Benchmarks/SyntheticBenchmarks.cs +++ b/Benchmarks/Open.Database.Extensions.Benchmarks/SyntheticBenchmarks.cs @@ -343,8 +343,8 @@ void WidthTwenty() // The ladder at widths 10 and 20: Gen_T is the generated reader on the twin with V2's member types (Title, Body, Tag and Blob non-nullable, read without a NULL // test, as V2 reads them), Ctl_T is the hand-written selector of that twin in the same assembly (GeneratedControl.cs), V2's reads cell for cell. They - // build a GenRowT20, not a SynRow. Gen_T enters through Map(RowMap) (the GeneratedRowMap hook: one bind per result set, SequentialAccess), Ctl_T through - // Map(Func) (Default). Expected: Gen_T = Ctl_T = V2, up to the row type, the access mode and interface (IDataRecord) versus virtual (DbDataReader) calls. + // build a GenRowT20, not a SynRow. Gen_T enters through Map(RowMap) (the GeneratedRowMap hook: one bind per result set), Ctl_T through + // Map(Func), both with default access. Expected: Gen_T = Ctl_T = V2, up to the row type and interface (IDataRecord) versus virtual (DbDataReader) calls. // At width 10 do not compare them with V2: V2 builds the 20-member SynRow there, the twin has ten members. [Benchmark] public object Gen_T_Sync() { _label = nameof(Gen_T_Sync); TenOrTwenty(); return SyntheticGenerated.GenT(Connection, Width); } diff --git a/Benchmarks/Open.Database.Extensions.Benchmarks/SyntheticGenerated.cs b/Benchmarks/Open.Database.Extensions.Benchmarks/SyntheticGenerated.cs index 5d36ce6d..4f26917a 100644 --- a/Benchmarks/Open.Database.Extensions.Benchmarks/SyntheticGenerated.cs +++ b/Benchmarks/Open.Database.Extensions.Benchmarks/SyntheticGenerated.cs @@ -13,7 +13,7 @@ namespace Open.Database.Extensions.Benchmarks; // Gen and GenD against V2: not like-for-like even at width 20. GenRow20 and GenRowD20 declare Title, Body, Tag and Blob nullable, so the generated reader // tests those four for NULL where V2 reads them with no test. The like-for-like bars are Gen_T and Ctl_T (the twin with V2's member types, Ctl_T's reads // V2's Read20 cell for cell) against V2, and Gen against Ctl. Gen and CtlH_T enter through Map(RowMap) (Core's GeneratedRowMap hook), the other controls and V2 through -// Map(Func): the same loop and the same per-row delegate invoke, but a RowMap query opens the reader with SequentialAccess and a selector with Default. +// Map(Func): the same loop and the same per-row delegate invoke, both with default access. // The twins of widths 1, 3, 5 and 10 have only that many members, while V2's Hand(width) builds a full SynRow, so at those widths the twin also allocates less // (fewer members) and nothing compares with V2 in time or in allocation. // diff --git a/Benchmarks/Open.Database.Extensions.Benchmarks/SyntheticVariants.cs b/Benchmarks/Open.Database.Extensions.Benchmarks/SyntheticVariants.cs index 71300521..2ffc3163 100644 --- a/Benchmarks/Open.Database.Extensions.Benchmarks/SyntheticVariants.cs +++ b/Benchmarks/Open.Database.Extensions.Benchmarks/SyntheticVariants.cs @@ -148,7 +148,7 @@ public static List V0(SyntheticConnection connection) // The drain the library's default makes before it closes the reader (RowReader.ReadThrough), so a NextResult cost is charged to every variant alike. while (reader.NextResult()) { } return rows; - }, CommandBehavior.SequentialAccess); + }, CommandBehavior.Default); public static ValueTask> V0Async(SyntheticConnection connection) => connection.Command(Sql).ExecuteReaderAsync>(static async reader => @@ -165,7 +165,7 @@ public static ValueTask> V0Async(SyntheticConnection connection) // The same drain as the sync V0 and as the library's default (which calls NextResult, not NextResultAsync, here). while (db.NextResult()) { } return rows; - }, CommandBehavior.SequentialAccess); + }, CommandBehavior.Default); // ---- V0b: V0, then convert the object[] rows to typed rows after the close ---------------------------------------------------------------- public static List V0b(SyntheticConnection connection) diff --git a/Benchmarks/Open.Database.Extensions.Benchmarks/SyntheticVariantsC.Widths.cs b/Benchmarks/Open.Database.Extensions.Benchmarks/SyntheticVariantsC.Widths.cs index f763ccd8..bdb055b9 100644 --- a/Benchmarks/Open.Database.Extensions.Benchmarks/SyntheticVariantsC.Widths.cs +++ b/Benchmarks/Open.Database.Extensions.Benchmarks/SyntheticVariantsC.Widths.cs @@ -1,5 +1,5 @@ // Generated by gen-c.ps1 (kept beside the BS-C notes, not in the repository): one hand-written method per catalog width, on purpose. -// A loop or a generic over the width would be a different thing to measure. Every cell is read once, in column order (SequentialAccess). +// A loop or a generic over the width would be a different thing to measure. Every cell is read once, in column order. using System.Collections; using System.Data.Common; diff --git a/Benchmarks/Open.Database.Extensions.Benchmarks/SyntheticVariantsC.cs b/Benchmarks/Open.Database.Extensions.Benchmarks/SyntheticVariantsC.cs index acf62331..a43414b7 100644 --- a/Benchmarks/Open.Database.Extensions.Benchmarks/SyntheticVariantsC.cs +++ b/Benchmarks/Open.Database.Extensions.Benchmarks/SyntheticVariantsC.cs @@ -286,7 +286,7 @@ public static List HandList(SyntheticConnection connection, FuncThe same loop on the sealed SyntheticReader: the cast is once per query, every call after it is direct. public static List HandListSyn(SyntheticConnection connection, Func map) @@ -299,7 +299,7 @@ public static List HandListSyn(SyntheticConnection connection, Func V9cDb(SyntheticConnection connection, Hands hands) => HandList(connection, hands.CDb); @@ -324,7 +324,7 @@ static Cap CaptureRows(SyntheticConnection connection, Func c var cap = read(db); while (db.NextResult()) { } return cap; - }, CommandBehavior.SequentialAccess); + }, CommandBehavior.Default); /// V9a on: the V6b-F function builds the massaged objects after the close, from the captured columns. public static List V9aOn(SyntheticConnection connection, Hands hands) diff --git a/Benchmarks/Open.Database.Extensions.Benchmarks/SyntheticVariantsF.cs b/Benchmarks/Open.Database.Extensions.Benchmarks/SyntheticVariantsF.cs index 8171db86..cacc8395 100644 --- a/Benchmarks/Open.Database.Extensions.Benchmarks/SyntheticVariantsF.cs +++ b/Benchmarks/Open.Database.Extensions.Benchmarks/SyntheticVariantsF.cs @@ -298,7 +298,7 @@ public static List F2u(UnsealedSyntheticConnection connection, FHands ha while (db.NextResult()) { } return list; - }, CommandBehavior.SequentialAccess); + }, CommandBehavior.Default); /// F4: V9c-Db's terminal (HandList) with the tree over DbDataReader. public static List F4(SyntheticConnection connection, FHands hands) => SyntheticVariantsC.HandList(connection, hands.F4);