Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions Benchmarks/Open.Database.Extensions.Benchmarks/GateBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ protected void Open()
// 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}");
Expand Down Expand Up @@ -210,9 +209,6 @@ protected void Check(string rung, ReadModeConnection connection, bool sequential
[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)
Expand All @@ -225,10 +221,7 @@ 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));
}
=> 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));
Expand Down Expand Up @@ -258,7 +251,7 @@ public override void VerifyAll()
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(Gen_T), Gen_T, generated: true);
CheckRung(nameof(Selector), Selector);
}

Expand All @@ -272,11 +265,7 @@ public override void VerifyAll()
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);
}
public void SetupGen_T() { Prepare(); CheckRung(nameof(Gen_T), Gen_T, generated: true); }

[GlobalSetup(Target = nameof(Selector))]
public void SetupSelector() { Prepare(); CheckRung(nameof(Selector), Selector); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Open.Database.Extensions.Benchmarks;

/// <summary>
/// The generated map against the hand-written reader and Dapper.AOT over the real databases, on one row type per width (10 and 20).
/// <c>GenD_T</c> (annotated) and <c>Gen_T</c> (not annotated; SQL Server only) are generated; <c>CtlH_T</c> is the same reads written by hand
/// <c>GenD_T</c> (annotated) and <c>Gen_T</c> (not annotated) are generated; <c>CtlH_T</c> is the same reads written by hand
/// with the same entry and access mode; <c>V2</c> is the hand-written selector; <c>V7a_T</c> is Dapper.AOT.
/// Setup reads each once and compares the rows with V2's, so no case is timed over wrong rows.
/// </summary>
Expand Down Expand Up @@ -48,7 +48,7 @@ public void Setup()
Same(nameof(GenD_T), expected, Generated(nameof(GenD_T), GenD_T));
Same(nameof(CtlH_T), expected, (IList)CtlH_T());
Same(nameof(V7a_T), expected, (IList)V7a_T());
if (Provider == RealProviderParams.SqlServer) Same(nameof(Gen_T), expected, Generated(nameof(Gen_T), Gen_T));
Same(nameof(Gen_T), expected, Generated(nameof(Gen_T), Gen_T));
}

// Present only in a build with -p:OdxGeneratorCounters=true (never a timed run): then a generated rung must be served by generated code.
Expand Down Expand Up @@ -110,13 +110,9 @@ public object GenD_T()

[Benchmark]
public object Gen_T()
{
// SQLite stores a Guid as text, which the generated reader of an undecorated model leaves to the runtime map.
if (Provider == RealProviderParams.Sqlite) throw new NotSupportedException("Gen_T is not served by generated code on SQLite.");
return Width == 10
=> Width == 10
? GeneratedReads.GenT10(_case.Timed.Command(RealProviderVariants.Sql))
: GeneratedReads.GenT20(_case.Timed.Command(RealProviderVariants.Sql));
}

[Benchmark]
public object V7a_T()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,15 +423,7 @@ public void Cleanup()
// The generated reader, the hand-written selector of the same row type, and Dapper.AOT building it: all on GenRowT20, whose members have the
// table's nullability. Width 20 only (ODX_RP_WIDTHS=20).
[Benchmark]
public object Gen_T_Sync()
{
_label = nameof(Gen_T_Sync);
WidthTwenty();

// SQLite stores a Guid as text, which the generated reader of an undecorated model leaves to the runtime map: this rung would measure that.
if (Provider == RealProviderParams.Sqlite) throw new NotSupportedException("Gen_T_Sync is not served by generated code on SQLite; GenD_T_Sync is.");
return GeneratedReads.GenT20(Case.Timed.Command(RealProviderVariants.Sql));
}
public object Gen_T_Sync() { _label = nameof(Gen_T_Sync); WidthTwenty(); return GeneratedReads.GenT20(Case.Timed.Command(RealProviderVariants.Sql)); }

// GenD_T: the decorated twin, read by the trusted generated reader at constant ordinals.
[Benchmark]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ public static int VerifyRealProviders()
{
// The rungs on the 20-column row type run at width 20 only.
if (width != 20 && method.Name is "Gen_T_Sync" or "GenD_T_Sync" or "Ctl_T_Sync" or "V7a_T_Sync") continue;
if (provider == RealProviderParams.Sqlite && method.Name == "Gen_T_Sync") continue; // Not a generated rung there (see the method).
recorder.Reset();
bool generated = method.Name is "Gen_T_Sync" or "GenD_T_Sync" && GeneratorCounters is not null;
long served = generated ? Counter("Served") : 0, declined = generated ? Counter("Declined") : 0;
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Post[] posts = await connectionFactory

## Generated row readers

This package carries a source generator. With C# 12 or later and the .NET 9.0.300 SDK or Visual Studio 17.14, or newer, a plain `Map<T>()` on a command or a reader gets its row reader written at build time, with nothing to add. While it is on, a model that declares every column's ordinal is read by position, unchecked. To switch it off, set `<OdxGenerateMaps>false</OdxGenerateMaps>` in the project. See [Generated readers](https://open-net-libraries.github.io/Open.Database.Extensions/articles/mapping.html#generated-readers).
This package carries a source generator. With C# 12 or later and the .NET 9.0.300 SDK or Visual Studio 17.14, or newer, a plain `Map<T>()` on a command or a reader gets its row reader written at build time, with nothing to add. A generated reader reads each member with the provider's getter for its type, without the runtime map's conversions, and a model that declares every column's ordinal is read by position, unchecked. To switch it off, set `<OdxGenerateMaps>false</OdxGenerateMaps>` in the project. See [Generated readers](https://open-net-libraries.github.io/Open.Database.Extensions/articles/mapping.html#generated-readers).

## Where to go next

Expand Down
Loading