From 8bc97547ff361a56c1cd602218638158ccbc96ea Mon Sep 17 00:00:00 2001 From: electricessence <5899455+electricessence@users.noreply.github.com> Date: Mon, 30 Nov 2026 16:17:41 -0800 Subject: [PATCH] Reads: sequential access is opt-in with SequentialAccess() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The library reads every query with the default access mode. It no longer asks for `CommandBehavior.SequentialAccess` on its own: mapped reads (`Map()`, `AsObjectArrays()`, `AsDictionaryRows()`), `AnyAsync`, `CountAsync`, `LoadTable` and `LoadTables` did, and `ToDataTable` and `ToDataTables` on an `IDbCommand` had it as the default of their `behavior` parameter, which is now `CommandBehavior.Default`. New: `SequentialAccess()`, one fluent opt-in. - On a command it applies to every reader the command opens from then on: reader callbacks, the `Map` terminals and the `DataTable` terminals. It stays on the command, and the caller's own flags stay. - It is also on the mapped views (`MappedCommand`, `MappedQuery` and its `Skip` and `Take` forms) and the mapped definitions (`MappedDbQuery`). - There is no attribute and no per-model or generator setting. Use it for very large text or binary values, above all one value copied as a stream with `reader.GetStream`. A selector given to `Map` must then read the columns in ascending order, or the provider throws. With `AsyncReads()` on a very large value, opt in: raw SqlClient with `Default` and `ReadAsync` took 48.0 s against 8.86 s for one 100 MB value; the library with default access was not measured. Docs: the XML docs and a compiled sample show the streaming case; the benchmark and async-read pages say which figures were measured with sequential access; release note. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 5.5 --- Source/Core/Core/RowsSources.cs | 3 +- Source/Core/ExpressiveCommandBase.cs | 43 +++- Source/Core/MappedDbQuery.cs | 34 ++- Source/Core/MappedQuery.cs | 59 +++-- Source/Core/MappedViews.cs | 5 + Source/Core/PublicAPI.Unshipped.txt | 11 + Source/Core/RowsForm.cs | 4 +- .../Core/Synchronous/SyncCommandExtensions.cs | 8 +- .../SyncExecuteReaderExtensions.cs | 4 +- .../AsyncReadsTests.cs | 2 +- .../ExecuteReaderEdgeTests.cs | 2 +- .../MappedQueryFirstSingleTests.cs | 2 +- .../MappedQueryReadThroughTests.cs | 6 +- .../MappedViewOwnershipTests.cs | 14 +- .../RowsFormTests.cs | 6 +- .../SequentialAccessOptInTests.cs | 223 ++++++++++++++++++ .../SequentialAccessOrderTests.cs | 2 +- .../SingleResultBeforeMapTests.cs | 6 +- docsite/articles/async-reads.md | 10 +- .../benchmarks/slow-links-and-large-values.md | 12 +- docsite/articles/expressive-commands.md | 11 + docsite/articles/mapping.md | 2 +- docsite/articles/performance.md | 3 + docsite/articles/release-notes.md | 1 + docsite/images/perf/perf-large-value.svg | 8 +- docsite/includes/perf/large-value.md | 4 +- docsite/perf-data/large-value.csv | 4 +- docsite/samples/ExpressiveCommands.cs | 24 ++ docsite/samples/Program.cs | 6 + docsite/tools/perf/New-PerfCharts.ps1 | 4 +- 30 files changed, 436 insertions(+), 87 deletions(-) create mode 100644 Tests/Open.Database.Extensions.Core.Tests/SequentialAccessOptInTests.cs diff --git a/Source/Core/Core/RowsSources.cs b/Source/Core/Core/RowsSources.cs index 36a2233d..33354438 100644 --- a/Source/Core/Core/RowsSources.cs +++ b/Source/Core/Core/RowsSources.cs @@ -3,8 +3,7 @@ namespace Open.Database.Extensions.Core; /// /// Reads a row without a model: one slot for each column, read as . /// -// GetValues reads each column once, in order, so a provider may stream the row -// (the read mode of a generated mapping applies: SequentialAccess). +// GetValues reads each column once, in order, so it also works with SequentialAccess(). static class ObjectRow { /// Reads the current row of a record. diff --git a/Source/Core/ExpressiveCommandBase.cs b/Source/Core/ExpressiveCommandBase.cs index e8df1b66..7508e53e 100644 --- a/Source/Core/ExpressiveCommandBase.cs +++ b/Source/Core/ExpressiveCommandBase.cs @@ -100,6 +100,7 @@ private protected sealed class CommandOptions public CancellationToken CancellationToken; public ushort Timeout = CommandTimeout.DEFAULT_SECONDS; public bool AsyncReads; + public bool SequentialAccess; } private protected CommandOptions? _options; @@ -741,6 +742,44 @@ public TThis SetTimeout(ushort seconds) return (TThis)this; } + /// Opens this command's readers with , for very large text or binary values. + /// + /// + /// The provider then streams each row instead of buffering it, and a column can be read once, in ascending order. + /// It applies to every reader this command opens from then on: a reader callback, the Map terminals (also of a view made before this call) + /// and the terminals. It stays on the command. + /// Without it the library reads with the default access mode. + /// + /// + /// The typical use is to copy one very large value as a stream: select the key columns first and the large column last, + /// and read it in a reader callback with . + /// A selector given to Map must read the columns in ascending order, or the provider throws. + /// + /// + /// + /// Copy one large value from a command made on a or a factory: + /// + /// await command + /// .SequentialAccess() + /// .ExecuteReaderAsync(async ValueTask (reader) => + /// { + /// if (!await reader.ReadAsync(cancellationToken)) return; + /// using Stream value = reader.GetStream(0); + /// await value.CopyToAsync(destination, cancellationToken); + /// }, cancellationToken: cancellationToken); + /// + /// + /// This instance for use in method chaining. + public TThis SequentialAccess() + { + EnsureOptions().SequentialAccess = true; + return (TThis)this; + } + + // The behavior a reader of this command is asked for: the caller's, and sequential access when SequentialAccess() was called. + CommandBehavior WithAccess(CommandBehavior behavior) + => _options is { SequentialAccess: true } ? behavior | CommandBehavior.SequentialAccess : behavior; + #region Derived parameter names /// @@ -1395,7 +1434,7 @@ internal TResult ExecuteReader(TState state, Func + return ExecuteCore((state, transform, behavior: WithAccess(behavior)), static (cmd, prior, s) => { ReaderAbandon.ArmFor(s.transform, cmd); CommandBehavior b = ConnectionExtensions.ReaderBehavior(prior, s.behavior); @@ -1498,7 +1537,7 @@ ValueTask IExecuteReader.ExecuteReaderAsync( => ExecuteReaderAsync(handler, behavior, default); ValueTask ExecuteReaderCoreAsync(TState state, Func> transform, CommandBehavior behavior, CancellationToken cancellationToken) - => ExecuteCoreAsync((state, transform, behavior, cancellationToken), static async (cmd, prior, s) => + => ExecuteCoreAsync((state, transform, behavior: WithAccess(behavior), cancellationToken), static async (cmd, prior, s) => { ReaderAbandon.ArmFor(s.transform, cmd); CommandBehavior b = ConnectionExtensions.ReaderBehavior(prior, s.behavior); diff --git a/Source/Core/MappedDbQuery.cs b/Source/Core/MappedDbQuery.cs index 429dcdb3..aa44bc4f 100644 --- a/Source/Core/MappedDbQuery.cs +++ b/Source/Core/MappedDbQuery.cs @@ -21,9 +21,9 @@ namespace Open.Database.Extensions; /// /// /// Set on the definition, for every query made from it: the map, , , , -/// and (on the before Map) -/// . A query made from it can still apply SingleResult, CancelOnEarlyStop, AsyncReads and -/// UsePool for one call. Chosen per call: the parameters, Skip and Take. +/// , and (on the before Map) +/// . A query made from it can still apply SingleResult, CancelOnEarlyStop, AsyncReads, +/// SequentialAccess and UsePool for one call. Chosen per call: the parameters, Skip and Take. /// /// /// The type each row is mapped to. @@ -35,9 +35,10 @@ public sealed class MappedDbQuery readonly ArrayPool? _pool; readonly bool _clearOnReturn; readonly bool _cancelOnEarlyStop; + readonly bool _sequentialAccess; internal MappedDbQuery(DbQuery definition, IRowSource source) - : this(definition, source, false, false, null, false, false) + : this(definition, source, false, false, null, false, false, false) { } @@ -48,7 +49,8 @@ internal MappedDbQuery(DbQuery definition, IRowSource source) bool asyncReads, ArrayPool? pool, bool clearOnReturn, - bool cancelOnEarlyStop) + bool cancelOnEarlyStop, + bool sequentialAccess) { Debug.Assert(definition is not null); Debug.Assert(source is not null); @@ -60,6 +62,7 @@ internal MappedDbQuery(DbQuery definition, IRowSource source) _pool = pool; _clearOnReturn = clearOnReturn; _cancelOnEarlyStop = cancelOnEarlyStop; + _sequentialAccess = sequentialAccess; } /// Gets the command definition under this mapped one. @@ -72,7 +75,7 @@ internal MappedDbQuery(DbQuery definition, IRowSource source) /// A definition that reads only the first result set. public MappedDbQuery SingleResult() - => new(Query, _source, true, _asyncReads, _pool, _clearOnReturn, _cancelOnEarlyStop); + => new(Query, _source, true, _asyncReads, _pool, _clearOnReturn, _cancelOnEarlyStop, _sequentialAccess); /// /// Cancels the command when a terminal stops before the last row, in every query made from this definition @@ -80,7 +83,7 @@ public MappedDbQuery SingleResult() /// /// A definition whose queries cancel their command on an early stop. public MappedDbQuery CancelOnEarlyStop() - => new(Query, _source, _singleResult, _asyncReads, _pool, _clearOnReturn, true); + => new(Query, _source, _singleResult, _asyncReads, _pool, _clearOnReturn, true, _sequentialAccess); /// /// Reads the rows with the asynchronous read of the provider, in every query made from this definition @@ -88,7 +91,15 @@ public MappedDbQuery CancelOnEarlyStop() /// /// A definition that reads asynchronously. public MappedDbQuery AsyncReads() - => new(Query, _source, _singleResult, true, _pool, _clearOnReturn, _cancelOnEarlyStop); + => new(Query, _source, _singleResult, true, _pool, _clearOnReturn, _cancelOnEarlyStop, _sequentialAccess); + + /// + /// Asks the reader for sequential access, in every query made from this definition + /// (see for when to use it). + /// + /// A definition whose queries read with sequential access. + public MappedDbQuery SequentialAccess() + => new(Query, _source, _singleResult, _asyncReads, _pool, _clearOnReturn, _cancelOnEarlyStop, true); /// /// Takes the arrays that hold the rows from , in every query made from this definition @@ -103,7 +114,7 @@ public MappedDbQuery UsePool(ArrayPool pool, bool clearOnReturn) if (pool is null) throw new ArgumentNullException(nameof(pool)); Contract.EndContractBlock(); - return new(Query, _source, _singleResult, _asyncReads, pool, clearOnReturn, _cancelOnEarlyStop); + return new(Query, _source, _singleResult, _asyncReads, pool, clearOnReturn, _cancelOnEarlyStop, _sequentialAccess); } /// @@ -194,6 +205,7 @@ internal MappedQuery View(DbQueryCall call) if (_singleResult) view = view.SingleResult(); if (_cancelOnEarlyStop) view = view.CancelOnEarlyStop(); if (_asyncReads) view = view.AsyncReads(); + if (_sequentialAccess) view = view.SequentialAccess(); if (_pool is not null) view = view.UsePool(_pool, _clearOnReturn); return view; } @@ -227,6 +239,10 @@ public MappedDbQuery CancelOnEarlyStop() public MappedDbQuery AsyncReads() => new(_definition.AsyncReads()); + /// + public MappedDbQuery SequentialAccess() + => new(_definition.SequentialAccess()); + /// public MappedDbQuery UsePool(ArrayPool pool, bool clearOnReturn) // The definition throws ArgumentNullException for a null pool. diff --git a/Source/Core/MappedQuery.cs b/Source/Core/MappedQuery.cs index 1886f99a..3f77304e 100644 --- a/Source/Core/MappedQuery.cs +++ b/Source/Core/MappedQuery.cs @@ -148,6 +148,7 @@ public static MappedQuery Map( /// to stop after the first result set and not read through the later ones; otherwise, . /// to read the rows of an asynchronous terminal with ReadAsync; otherwise, , which reads them with Read. /// to cancel the command when a terminal stops before the last row; otherwise, . +/// to ask the reader for ; otherwise, . /// The pool, the clear rule, the chunk sizes and the bin the pooling terminals use. readonly struct MappedQueryCore( IExecuteReader? command, @@ -158,22 +159,17 @@ readonly struct MappedQueryCore( bool singleResult, bool asyncReads, bool cancelOnEarlyStop, + bool sequentialAccess, ChunkConfig config) : IEquatable> { - /// - /// The reader behavior of a generated mapping. - /// - // Generated mappings read each column once, in order, so the provider may stream the row. - // A caller-supplied selector may read in any order, so it runs with the default access mode. - const CommandBehavior GeneratedMapping = CommandBehavior.SingleResult | CommandBehavior.SequentialAccess; - readonly IRowSource _source = source; readonly int _skip = skip; readonly int _take = take; // -1 == unbounded. readonly bool _singleResult = singleResult; // SingleResult() was called: stop after the first result set and do not read through the rest. readonly bool _asyncReads = asyncReads; // AsyncReads() was called: the rows of an async terminal are read with ReadAsync (the default is Read). readonly bool _cancelOnEarlyStop = cancelOnEarlyStop; // CancelOnEarlyStop() was called: see ReaderAbandon. + readonly bool _sequentialAccess = sequentialAccess; // SequentialAccess() was called on the query. /// /// The command, or for a default value. @@ -248,6 +244,7 @@ public bool Equals(MappedQueryCore other) && _singleResult == other._singleResult && _asyncReads == other._asyncReads && _cancelOnEarlyStop == other._cancelOnEarlyStop + && _sequentialAccess == other._sequentialAccess && ReferenceEquals(Config, other.Config); public override bool Equals(object? obj) @@ -262,6 +259,7 @@ public override int GetHashCode() h = h * 31 + _skip; h = h * 31 + _take; return h * 31 + + (_sequentialAccess ? 8 : 0) + (_cancelOnEarlyStop ? 4 : 0) + (_singleResult ? 2 : 0) + (_asyncReads ? 1 : 0) @@ -273,15 +271,18 @@ public override int GetHashCode() /// Gets the the reader is asked for. /// // Without SingleResult() the reader is asked for every result set, because a terminal reads through the later ones to report their failures. - CommandBehavior Behavior => _singleResult - ? (_source is SelectorSource ? CommandBehavior.SingleResult : GeneratedMapping) - : (_source is SelectorSource ? CommandBehavior.Default : CommandBehavior.SequentialAccess); + // SequentialAccess() called on the command is added by the command itself when it opens the reader. + CommandBehavior Behavior + => (_singleResult ? CommandBehavior.SingleResult : CommandBehavior.Default) + | (_sequentialAccess ? CommandBehavior.SequentialAccess : CommandBehavior.Default); - public MappedQueryCore WithSingleResult() => Checked(new(_command, _call, _source, _skip, _take, true, _asyncReads, _cancelOnEarlyStop, Config)); + public MappedQueryCore WithSingleResult() => Checked(new(_command, _call, _source, _skip, _take, true, _asyncReads, _cancelOnEarlyStop, _sequentialAccess, Config)); - public MappedQueryCore WithAsyncReads() => Checked(new(_command, _call, _source, _skip, _take, _singleResult, true, _cancelOnEarlyStop, Config)); + public MappedQueryCore WithAsyncReads() => Checked(new(_command, _call, _source, _skip, _take, _singleResult, true, _cancelOnEarlyStop, _sequentialAccess, Config)); - public MappedQueryCore WithCancelOnEarlyStop() => Checked(new(_command, _call, _source, _skip, _take, _singleResult, _asyncReads, true, Config)); + public MappedQueryCore WithCancelOnEarlyStop() => Checked(new(_command, _call, _source, _skip, _take, _singleResult, _asyncReads, true, _sequentialAccess, Config)); + + public MappedQueryCore WithSequentialAccess() => Checked(new(_command, _call, _source, _skip, _take, _singleResult, _asyncReads, _cancelOnEarlyStop, true, Config)); /// /// Gets the configuration the query was given. @@ -318,11 +319,11 @@ public MappedQueryCore WithPool(ArrayPool pool, bool clearOnReturn) /// The configuration to use. /// A copy of the query that uses . public MappedQueryCore WithConfig(ChunkConfig config) - => Checked(new(_command, _call, _source, _skip, _take, _singleResult, _asyncReads, _cancelOnEarlyStop, config)); + => Checked(new(_command, _call, _source, _skip, _take, _singleResult, _asyncReads, _cancelOnEarlyStop, _sequentialAccess, config)); /// Returns the same query over another call. public MappedQueryCore WithCall(DbQueryCall call) - => new(null, call, _source, _skip, _take, _singleResult, _asyncReads, _cancelOnEarlyStop, Config); + => new(null, call, _source, _skip, _take, _singleResult, _asyncReads, _cancelOnEarlyStop, _sequentialAccess, Config); public MappedQueryCore WithSkip(int count) => count >= 0 @@ -335,6 +336,7 @@ public MappedQueryCore WithSkip(int count) _singleResult, _asyncReads, _cancelOnEarlyStop, + _sequentialAccess, Config)) : throw new ArgumentOutOfRangeException(nameof(count), count, "Cannot be negative."); @@ -357,6 +359,7 @@ public MappedQueryCore WithTake(int count) _singleResult, _asyncReads, _cancelOnEarlyStop, + _sequentialAccess, Config)) : throw new ArgumentOutOfRangeException(nameof(count), count, "Cannot be negative."); @@ -801,9 +804,6 @@ static async (reader, s) => return found ? row! : throw RowReader.NoRows(nameof(SingleAsync)); } - // AnyAsync and CountAsync map nothing and touch no column, so the provider may stream the row whatever the source is. - CommandBehavior NoColumnBehavior => _singleResult ? GeneratedMapping : CommandBehavior.SequentialAccess; - public ValueTask AnyAsync(CancellationToken cancellationToken) { ReaderAbandon? abandon = NewAbandon(); @@ -813,10 +813,7 @@ public ValueTask AnyAsync(CancellationToken cancellationToken) (_skip, _take, _asyncReads, abandon, token), static (reader, s) => RowReader.AnyAsync( reader, s._skip, s._take, s._asyncReads, s.token, s.abandon), - // As FirstBehavior. - UseSingleRow - ? NoColumnBehavior | CommandBehavior.SingleRow - : NoColumnBehavior, + FirstBehavior, abandon, linked, token); } @@ -829,7 +826,7 @@ public ValueTask CountAsync(CancellationToken cancellationToken) (_skip, _take, _asyncReads, abandon, token), static (reader, s) => RowReader.CountAsync( reader, s._skip, s._take, s._asyncReads, s.token, s.abandon), - NoColumnBehavior, abandon, linked, token); + Behavior, abandon, linked, token); } public ImmutableArray ToImmutableArray() @@ -1213,6 +1210,16 @@ public readonly record struct MappedQuery // A selector map (Map(Func)) on one very large value reads slower and uses more memory with ReadAsync. public MappedQuery AsyncReads() => new(_core.WithAsyncReads()); + /// Asks the reader for , for very large text or binary values. + /// + /// The provider then streams each row instead of buffering it, and a column can be read once, in ascending order: + /// a selector given to Map must read the columns in that order, or the provider throws. + /// Without it the library reads with the default access mode. It can be called in any order with Skip, Take and SingleResult. + /// To read one large value as a stream, call SequentialAccess() on the command and use reader.GetStream in a reader callback. + /// + /// The same query, reading with sequential access. + public MappedQuery SequentialAccess() => new(_core.WithSequentialAccess()); + /// /// Chooses the pool this query's pooled arrays are rented from, and /// whether their rows are cleared when they go back. @@ -1767,6 +1774,9 @@ public readonly record struct MappedQueryWithSkip /// public MappedQueryWithSkip AsyncReads() => new(_core.WithAsyncReads()); + /// + public MappedQueryWithSkip SequentialAccess() => new(_core.WithSequentialAccess()); + /// public MappedQueryWithSkip UsePool(ArrayPool pool, bool clearOnReturn) => new(_core.WithPool(pool, clearOnReturn)); @@ -1907,6 +1917,9 @@ public readonly record struct MappedQueryWithTake /// public MappedQueryWithTake AsyncReads() => new(_core.WithAsyncReads()); + /// + public MappedQueryWithTake SequentialAccess() => new(_core.WithSequentialAccess()); + /// public MappedQueryWithTake UsePool(ArrayPool pool, bool clearOnReturn) => new(_core.WithPool(pool, clearOnReturn)); diff --git a/Source/Core/MappedViews.cs b/Source/Core/MappedViews.cs index fefcca2b..70b1f86a 100644 --- a/Source/Core/MappedViews.cs +++ b/Source/Core/MappedViews.cs @@ -352,6 +352,7 @@ static MappedQueryCore NewCore( singleResult, asyncReads, false, + false, Defaults.Config); /// @@ -885,6 +886,10 @@ public MappedCommand CancelOnEarlyStop() public MappedCommand AsyncReads() => new(_core.WithAsyncReads()); + /// + public MappedCommand SequentialAccess() + => new(_core.WithSequentialAccess()); + /// public MappedCommand UsePool(ArrayPool pool, bool clearOnReturn) => new(_core.WithPool(pool, clearOnReturn)); diff --git a/Source/Core/PublicAPI.Unshipped.txt b/Source/Core/PublicAPI.Unshipped.txt index e9a375d7..ca9ac00a 100644 --- a/Source/Core/PublicAPI.Unshipped.txt +++ b/Source/Core/PublicAPI.Unshipped.txt @@ -2,3 +2,14 @@ Open.Database.Extensions.Generation.GeneratedRowMap static Open.Database.Extensions.Generation.GeneratedRowMap.Create(System.Func?>! binder) -> Open.Database.Extensions.RowMap! Open.Database.Extensions.PooledBuffer.AsAsyncEnumerable(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Collections.Generic.IAsyncEnumerable! +Open.Database.Extensions.ExpressiveCommandBase.SequentialAccess() -> TThis! +Open.Database.Extensions.MappedCommand.SequentialAccess() -> Open.Database.Extensions.MappedCommand +Open.Database.Extensions.MappedDbQuery.SequentialAccess() -> Open.Database.Extensions.MappedDbQuery! +Open.Database.Extensions.MappedDbQuery.SequentialAccess() -> Open.Database.Extensions.MappedDbQuery! +Open.Database.Extensions.MappedQuery.SequentialAccess() -> Open.Database.Extensions.MappedQuery +Open.Database.Extensions.MappedQueryWithSkip.SequentialAccess() -> Open.Database.Extensions.MappedQueryWithSkip +Open.Database.Extensions.MappedQueryWithTake.SequentialAccess() -> Open.Database.Extensions.MappedQueryWithTake +*REMOVED*static Open.Database.Extensions.Synchronous.SyncCommandExtensions.ToDataTable(this System.Data.IDbCommand! command, System.Data.CommandBehavior behavior = System.Data.CommandBehavior.SequentialAccess) -> System.Data.DataTable! +static Open.Database.Extensions.Synchronous.SyncCommandExtensions.ToDataTable(this System.Data.IDbCommand! command, System.Data.CommandBehavior behavior = System.Data.CommandBehavior.Default) -> System.Data.DataTable! +*REMOVED*static Open.Database.Extensions.Synchronous.SyncCommandExtensions.ToDataTables(this System.Data.IDbCommand! command, System.Data.CommandBehavior behavior = System.Data.CommandBehavior.SequentialAccess) -> System.Collections.Generic.List! +static Open.Database.Extensions.Synchronous.SyncCommandExtensions.ToDataTables(this System.Data.IDbCommand! command, System.Data.CommandBehavior behavior = System.Data.CommandBehavior.Default) -> System.Collections.Generic.List! diff --git a/Source/Core/RowsForm.cs b/Source/Core/RowsForm.cs index 256a246b..6a7564e6 100644 --- a/Source/Core/RowsForm.cs +++ b/Source/Core/RowsForm.cs @@ -8,11 +8,11 @@ public static partial class CoreExtensions /// /// /// Everything after it is the mapped view: the terminals, Skip and Take, SingleResult(), - /// AsyncReads() and UsePool are the ones Map<T>() has, and a later result set is read through + /// AsyncReads(), SequentialAccess() and UsePool are the ones Map<T>() has, and a later result set is read through /// the same way. /// Each row is one new object?[] with a slot for each column (a database NULL is ). /// The row arrays belong to the caller; only the buffers that hold the rows are pooled, and those are cleared when they go back. - /// The columns are read once, in order, so a provider may stream a row. + /// The columns are read once, in order, so it also works with SequentialAccess(). /// The result carries no column names: use when you need them. /// /// diff --git a/Source/Core/Synchronous/SyncCommandExtensions.cs b/Source/Core/Synchronous/SyncCommandExtensions.cs index 81b449be..055d551b 100644 --- a/Source/Core/Synchronous/SyncCommandExtensions.cs +++ b/Source/Core/Synchronous/SyncCommandExtensions.cs @@ -13,11 +13,11 @@ public static class SyncCommandExtensions /// /// /// The behavior to use with the data reader. - /// The default is . + /// The default is ; pass to opt in to it. /// /// A that holds the result set. /// - public static DataTable ToDataTable(this IDbCommand command, CommandBehavior behavior = CommandBehavior.SequentialAccess) + public static DataTable ToDataTable(this IDbCommand command, CommandBehavior behavior = CommandBehavior.Default) { if (command is null) throw new ArgumentNullException(nameof(command)); Contract.EndContractBlock(); @@ -38,11 +38,11 @@ public static DataTable ToDataTable(this IDbCommand command, CommandBehavior beh /// /// /// The behavior to use with the data reader. - /// The default is . + /// The default is ; pass to opt in to it. /// /// A list of tables, one for each result set. /// - public static List ToDataTables(this IDbCommand command, CommandBehavior behavior = CommandBehavior.SequentialAccess) + public static List ToDataTables(this IDbCommand command, CommandBehavior behavior = CommandBehavior.Default) { if (command is null) throw new ArgumentNullException(nameof(command)); Contract.EndContractBlock(); diff --git a/Source/Core/Synchronous/SyncExecuteReaderExtensions.cs b/Source/Core/Synchronous/SyncExecuteReaderExtensions.cs index 206169e2..be904d06 100644 --- a/Source/Core/Synchronous/SyncExecuteReaderExtensions.cs +++ b/Source/Core/Synchronous/SyncExecuteReaderExtensions.cs @@ -13,7 +13,7 @@ public static class SyncExecuteReaderExtensions public static DataTable LoadTable(this IExecuteReader command) => command.AsSync().ExecuteReader( reader => reader.ToDataTable(), - CommandBehavior.SequentialAccess | CommandBehavior.SingleResult); + CommandBehavior.SingleResult); /// /// Loads each result set of the command into its own . @@ -27,5 +27,5 @@ public static DataTable LoadTable(this IExecuteReader command) public static List LoadTables(this IExecuteReader command) => command.AsSync().ExecuteReader( reader => reader.ToDataTables(), - CommandBehavior.SequentialAccess); + CommandBehavior.Default); } diff --git a/Tests/Open.Database.Extensions.Core.Tests/AsyncReadsTests.cs b/Tests/Open.Database.Extensions.Core.Tests/AsyncReadsTests.cs index 1e1da4ce..550d789f 100644 --- a/Tests/Open.Database.Extensions.Core.Tests/AsyncReadsTests.cs +++ b/Tests/Open.Database.Extensions.Core.Tests/AsyncReadsTests.cs @@ -250,7 +250,7 @@ public static async Task TheAccessMode_IsPinned_WithAndWithoutAsyncReads(bool op await view.ToListAsync(token); CommandBehavior used = Assert.Single(command.Behaviors); - Assert.Equal(generated, used.HasFlag(CommandBehavior.SequentialAccess)); + Assert.False(used.HasFlag(CommandBehavior.SequentialAccess)); Assert.Equal(singleResult, used.HasFlag(CommandBehavior.SingleResult)); } diff --git a/Tests/Open.Database.Extensions.Core.Tests/ExecuteReaderEdgeTests.cs b/Tests/Open.Database.Extensions.Core.Tests/ExecuteReaderEdgeTests.cs index 6b8bb19a..6ea9c9be 100644 --- a/Tests/Open.Database.Extensions.Core.Tests/ExecuteReaderEdgeTests.cs +++ b/Tests/Open.Database.Extensions.Core.Tests/ExecuteReaderEdgeTests.cs @@ -24,7 +24,7 @@ public static void LoadTable_LoadsTheFirstResultSet_AskingTheProviderForASingleO Assert.Equal([1, 2], loaded.Rows.Cast().Select(r => (int)r[0]).ToArray()); CommandBehavior behavior = Assert.Single(command.Behaviors); Assert.True(behavior.HasFlag(CommandBehavior.SingleResult)); - Assert.True(behavior.HasFlag(CommandBehavior.SequentialAccess)); + Assert.False(behavior.HasFlag(CommandBehavior.SequentialAccess)); } // ---- argument guards ---- diff --git a/Tests/Open.Database.Extensions.Core.Tests/MappedQueryFirstSingleTests.cs b/Tests/Open.Database.Extensions.Core.Tests/MappedQueryFirstSingleTests.cs index e10f4312..13f96c3e 100644 --- a/Tests/Open.Database.Extensions.Core.Tests/MappedQueryFirstSingleTests.cs +++ b/Tests/Open.Database.Extensions.Core.Tests/MappedQueryFirstSingleTests.cs @@ -27,7 +27,7 @@ static FakeExecuteReader Command(int rows) => new(() => Reader(Rows(rows))); // A selector query asks the provider for exactly the flags the caller's - // calls give it (a generated mapping adds SequentialAccess). + // calls give it. static MappedQuery Query(FakeExecuteReader command) => command.Map(r => r.GetInt32(0)); diff --git a/Tests/Open.Database.Extensions.Core.Tests/MappedQueryReadThroughTests.cs b/Tests/Open.Database.Extensions.Core.Tests/MappedQueryReadThroughTests.cs index 285f63c4..ccb26a79 100644 --- a/Tests/Open.Database.Extensions.Core.Tests/MappedQueryReadThroughTests.cs +++ b/Tests/Open.Database.Extensions.Core.Tests/MappedQueryReadThroughTests.cs @@ -273,7 +273,7 @@ public static void WithoutSingleResult_TheFlagsDropSingleResultAndSingleRow() Query(command).Take(1).FirstOrDefault(); command.Map().ToList(); - Assert.Equal([CommandBehavior.Default, CommandBehavior.Default, CommandBehavior.SequentialAccess], command.Behaviors); + Assert.Equal([CommandBehavior.Default, CommandBehavior.Default, CommandBehavior.Default], command.Behaviors); } [Fact] @@ -297,7 +297,7 @@ public static void SingleResult_OnEachType_AndAnywhereInTheChain_RestoresTheFlag } [Fact] - public static async Task SingleResult_AsyncTerminals_NeverCallNextResult_AndAGeneratedMappingKeepsSequentialAccess() + public static async Task SingleResult_AsyncTerminals_NeverCallNextResult_AndAddNoSequentialAccess() { FakeExecuteReader command = Command(2, out Func reader, failAt: 1); @@ -307,7 +307,7 @@ public static async Task SingleResult_AsyncTerminals_NeverCallNextResult_AndAGen await foreach (int _ in Query(command).SingleResult().Stream(Timeout.InfiniteTimeSpan, Ct)) { } Assert.Equal( - [CommandBehavior.SingleResult, CommandBehavior.SingleResult | CommandBehavior.SequentialAccess, CommandBehavior.SingleResult | CommandBehavior.SingleRow, CommandBehavior.SingleResult], + [CommandBehavior.SingleResult, CommandBehavior.SingleResult, CommandBehavior.SingleResult | CommandBehavior.SingleRow, CommandBehavior.SingleResult], command.Behaviors); Assert.Equal(0, reader().NextResultCalls); } diff --git a/Tests/Open.Database.Extensions.Core.Tests/MappedViewOwnershipTests.cs b/Tests/Open.Database.Extensions.Core.Tests/MappedViewOwnershipTests.cs index 8e4e2411..7e42042d 100644 --- a/Tests/Open.Database.Extensions.Core.Tests/MappedViewOwnershipTests.cs +++ b/Tests/Open.Database.Extensions.Core.Tests/MappedViewOwnershipTests.cs @@ -261,7 +261,7 @@ public static void ACommandWithoutAReaderThatIsADbCommand_RunsSynchronously() Assert.Equal("Open,ExecuteReader,DisposeReader,Close", probe.Log); Assert.Equal( - CommandBehavior.SequentialAccess | CommandBehavior.CloseConnection, + CommandBehavior.CloseConnection, probe.Behaviors.Single()); } @@ -276,7 +276,7 @@ public static async Task ACommandThatIsNotADbCommand_RunsAsyncTerminalsToo() Assert.Single(await probe.Command.Map().ToListAsync(Ct)); Assert.Equal("ExecuteReader,DisposeReader", probe.Log); - Assert.Equal(CommandBehavior.SequentialAccess, probe.Behaviors.Single()); + Assert.Equal(CommandBehavior.Default, probe.Behaviors.Single()); } // ---- behaviors and read-through ---- @@ -293,11 +293,9 @@ public static void TheBehaviors_AreThoseOfAnExpressiveCommandsMappedQuery() Assert.Equal( [ - CommandBehavior.SequentialAccess | CommandBehavior.CloseConnection, - CommandBehavior.SingleResult | CommandBehavior.SequentialAccess - | CommandBehavior.CloseConnection, - CommandBehavior.SingleResult | CommandBehavior.SequentialAccess - | CommandBehavior.SingleRow | CommandBehavior.CloseConnection, + CommandBehavior.CloseConnection, + CommandBehavior.SingleResult | CommandBehavior.CloseConnection, + CommandBehavior.SingleResult | CommandBehavior.SingleRow | CommandBehavior.CloseConnection, CommandBehavior.CloseConnection, CommandBehavior.SingleResult | CommandBehavior.CloseConnection, ], @@ -308,7 +306,7 @@ public static void TheBehaviors_AreThoseOfAnExpressiveCommandsMappedQuery() open.Map(r => r.GetInt32(0)).ToList(); Assert.Equal( - [CommandBehavior.SequentialAccess, CommandBehavior.Default], + [CommandBehavior.Default, CommandBehavior.Default], open.Behaviors); } diff --git a/Tests/Open.Database.Extensions.Core.Tests/RowsFormTests.cs b/Tests/Open.Database.Extensions.Core.Tests/RowsFormTests.cs index c1d98343..ec7387a6 100644 --- a/Tests/Open.Database.Extensions.Core.Tests/RowsFormTests.cs +++ b/Tests/Open.Database.Extensions.Core.Tests/RowsFormTests.cs @@ -229,7 +229,7 @@ static DictionaryRow FirstRow(string sql) // ---- the read: mode, later sets, SingleResult, pooling ---- [Fact] - public static async Task TheRowsFormReadsEveryColumnOnce_InOrder_WithSequentialAccess() + public static async Task TheRowsFormReadsWithDefaultAccess_AndSequentialOnlyOnRequest() { var behaviors = new List(); static DbDataReader Reader() => FakeReader.CreateDb(["a", "b"], [1, "x"]); @@ -238,12 +238,12 @@ public static async Task TheRowsFormReadsEveryColumnOnce_InOrder_WithSequentialA await first.AsObjectArrays().ToListAsync(Ct); behaviors.AddRange(first.Behaviors); var second = new FakeDbCommand(new FakeDbConnection(), Reader); - await second.AsDictionaryRows().SingleResult().ToListAsync(Ct); + await second.AsDictionaryRows().SingleResult().SequentialAccess().ToListAsync(Ct); behaviors.AddRange(second.Behaviors); // The library adds CloseConnection when it opened the connection itself: not part of the read mode. Assert.Equal( - [CommandBehavior.SequentialAccess, CommandBehavior.SingleResult | CommandBehavior.SequentialAccess], + [CommandBehavior.Default, CommandBehavior.SingleResult | CommandBehavior.SequentialAccess], behaviors.Select(static b => b & ~CommandBehavior.CloseConnection)); } diff --git a/Tests/Open.Database.Extensions.Core.Tests/SequentialAccessOptInTests.cs b/Tests/Open.Database.Extensions.Core.Tests/SequentialAccessOptInTests.cs new file mode 100644 index 00000000..937bb022 --- /dev/null +++ b/Tests/Open.Database.Extensions.Core.Tests/SequentialAccessOptInTests.cs @@ -0,0 +1,223 @@ +#nullable enable + +using Open.Database.Extensions.Synchronous; +using System.Buffers; + +namespace Open.Database.Extensions.Tests; + +// The library reads with CommandBehavior.Default; SequentialAccess() is the one way to ask a reader for sequential access. +// It is on a command (every reader it opens) and on every mapped view and definition. +[ExcludeFromCodeCoverage] +public static class SequentialAccessOptInTests +{ + static CancellationToken Ct => TestContext.Current.CancellationToken; + + // A reader that reports its column types, as the DataTable terminals need. + static DataTableReader OneRow() + { + var table = new DataTable(); + table.Columns.Add("Id", typeof(int)); + table.Rows.Add(1); + return table.CreateDataReader(); + } + + // An expressive command whose readers record what they were asked for. The connection is open, so nothing adds CloseConnection. + static ExpressiveDbCommand Expressive(out List behaviors) + { + var command = new FakeDbCommand(null, OneRow); + var connection = new DerivedParameterNameTests.OpenDbConnection(command); + command.Connection = connection; + behaviors = command.Behaviors; + return connection.Command("select Id from t"); + } + + static FakeDbCommand Raw() + { + var connection = new FakeDbConnection(); + connection.SetState(ConnectionState.Open); + return new FakeDbCommand(connection, static () => FakeReader.CreateDb(["Id"], [1])); + } + + static bool Sequential(CommandBehavior behavior) => behavior.HasFlag(CommandBehavior.SequentialAccess); + + [Fact] + public static async Task WithoutTheCall_NothingAsksForSequentialAccess() + { + ExpressiveDbCommand command = Expressive(out List behaviors); + + command.Map().ToList(); + command.Map(static r => r.GetInt32(0)).ToList(); + await command.Map().ToListAsync(Ct); + await command.Map().AnyAsync(Ct); + await command.Map().CountAsync(Ct); + command.ExecuteReader(static r => r.Read()); + await command.ExecuteReaderAsync(static r => r.Read(), cancellationToken: Ct); + command.LoadTable(); + command.LoadTables(); + + Assert.Equal(9, behaviors.Count); + Assert.DoesNotContain(behaviors, Sequential); + } + + [Fact] + public static async Task OnTheCommand_EveryReaderItOpensIsSequential() + { + ExpressiveDbCommand command = Expressive(out List behaviors); + Assert.Same(command, command.SequentialAccess()); + + command.Map().ToList(); + command.Map(static r => r.GetInt32(0)).ToList(); + await command.Map().ToListAsync(Ct); + await command.Map().AnyAsync(Ct); + await command.Map().CountAsync(Ct); + command.ExecuteReader(static r => r.Read()); + await command.ExecuteReaderAsync(static r => r.Read(), cancellationToken: Ct); + command.LoadTable(); + command.LoadTables(); + + Assert.Equal(9, behaviors.Count); + Assert.All(behaviors, static b => Assert.True(Sequential(b))); + } + + [Fact] + public static void OnTheCommand_TheCallersOwnFlagsStay() + { + ExpressiveDbCommand command = Expressive(out List behaviors); + + command.SequentialAccess().ExecuteReader(static r => r.Read(), CommandBehavior.SingleResult); + + Assert.Equal(CommandBehavior.SingleResult | CommandBehavior.SequentialAccess, Assert.Single(behaviors)); + } + + [Fact] + public static async Task OnEveryMappedView_InAnyOrder_ItReachesTheReader() + { + ExpressiveDbCommand command = Expressive(out List behaviors); + FakeDbCommand raw = Raw(); + IDbCommand plain = raw; + + command.Map().SequentialAccess().ToList(); + command.Map().Skip(0).SequentialAccess().ToList(); + command.Map().Take(1).SequentialAccess().ToList(); + command.Map().SequentialAccess().Skip(0).Take(1).ToList(); + command.Map().SequentialAccess().SingleResult().FirstOrDefault(); + await command.Map().SequentialAccess().AsyncReads().ToListAsync(Ct); + await command.Map().SequentialAccess().CountAsync(Ct); + plain.Map().SequentialAccess().ToList(); + plain.Map(static r => r.GetInt32(0)).SingleResult().SequentialAccess().ToList(); + + Assert.Equal(7, behaviors.Count); + Assert.Equal(2, raw.Behaviors.Count); + Assert.All(behaviors.Concat(raw.Behaviors), static b => Assert.True(Sequential(b))); + Assert.Equal(CommandBehavior.SingleResult | CommandBehavior.SingleRow | CommandBehavior.SequentialAccess, behaviors[4]); + } + + [Fact] + public static void OnAQuery_ItDoesNotChangeTheCommand() + { + ExpressiveDbCommand command = Expressive(out List behaviors); + + command.Map().SequentialAccess().ToList(); + command.Map().ToList(); + + Assert.True(Sequential(behaviors[0])); + Assert.False(Sequential(behaviors[1])); + } + + [Fact] + public static void OnADefinition_ItReachesItsQueries() + { + var command = new FakeDbCommand(null, static () => FakeReader.CreateDb(["Id"], [1])); + var connection = new DerivedParameterNameTests.OpenDbConnection(command); + command.Connection = connection; + MappedDbQuery definition = DbQuery.Text("select Id from t").Map(); + + definition.SequentialAccess().Using(connection).ToList(); + definition.Using(connection).SequentialAccess().ToList(); + definition.SequentialAccess().SingleResult().Using(connection).ToList(); + definition.Using(connection).ToList(); + + Assert.Equal([true, true, true, false], command.Behaviors.Select(Sequential)); + } + + [Fact] + public static async Task TheViewsOtherChoices_DoNotDropIt() + { + ExpressiveDbCommand command = Expressive(out List behaviors); + FakeDbCommand raw = Raw(); + IDbCommand plain = raw; + + command.Map().SequentialAccess().UsePool(ArrayPool.Shared, false).ToList(); + await plain.Map().SequentialAccess().ToListAsync(Ct); + + Assert.All(behaviors.Concat(raw.Behaviors), static b => Assert.True(Sequential(b))); + Assert.Equal(2, behaviors.Count + raw.Behaviors.Count); + + // CancelOnEarlyStop() asks the command for its parameters, which this fake has none of: the queries are compared instead. + MappedQuery query = command.Map(); + Assert.Equal(query.CancelOnEarlyStop().SequentialAccess(), query.SequentialAccess().CancelOnEarlyStop()); + Assert.NotEqual(query.CancelOnEarlyStop(), query.SequentialAccess().CancelOnEarlyStop()); + } + + // Unlike AsyncReads(), which Map() takes from the command, this is asked when the reader is opened. + [Fact] + public static void OnTheCommand_ItReachesAViewMadeBefore() + { + ExpressiveDbCommand command = Expressive(out List behaviors); + MappedQuery view = command.Map(); + + command.SequentialAccess(); + view.ToList(); + + Assert.True(Sequential(Assert.Single(behaviors))); + } + + readonly record struct Key(int Id); + + [Fact] + public static void OnATypedOrUnboundDefinition_ItIsTheSameAsOnTheQuery() + { + var connection = new FakeDbConnection(); + MappedDbQuery definition = DbQuery.Text("select Id from t where Id = @Id").Map(); + MappedDbQuery typed = definition.Params(); + + Assert.Equal( + typed.Using(connection).AddParams(new Key(1)).SequentialAccess(), + typed.SequentialAccess().Using(connection).AddParams(new Key(1))); + Assert.NotEqual( + typed.Using(connection).AddParams(new Key(1)), + typed.SequentialAccess().Using(connection).AddParams(new Key(1))); + Assert.Equal( + definition.AddParam("Id", 1).Using(connection).SequentialAccess(), + definition.SequentialAccess().AddParam("Id", 1).Using(connection)); + Assert.NotEqual( + definition.AddParam("Id", 1).Using(connection), + definition.SequentialAccess().AddParam("Id", 1).Using(connection)); + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public static void TheDataTableTerminalsOfARawCommand_DefaultToDefaultAccess(bool every) + { + var connection = new FakeDbConnection(); + connection.SetState(ConnectionState.Open); + var command = new FakeDbCommand(connection, OneRow); + IDbCommand raw = command; + + if (every) raw.ToDataTables(); + else raw.ToDataTable(); + + Assert.Equal(CommandBehavior.Default, Assert.Single(command.Behaviors)); + } + + [Fact] + public static void TwoQueriesThatDifferOnlyInIt_AreNotEqual() + { + ExpressiveDbCommand command = Expressive(out _); + MappedQuery query = command.Map(); + + Assert.NotEqual(query, query.SequentialAccess()); + Assert.Equal(query.SequentialAccess(), query.SequentialAccess()); + } +} diff --git a/Tests/Open.Database.Extensions.Core.Tests/SequentialAccessOrderTests.cs b/Tests/Open.Database.Extensions.Core.Tests/SequentialAccessOrderTests.cs index 2efab642..2ecbb47f 100644 --- a/Tests/Open.Database.Extensions.Core.Tests/SequentialAccessOrderTests.cs +++ b/Tests/Open.Database.Extensions.Core.Tests/SequentialAccessOrderTests.cs @@ -2,7 +2,7 @@ namespace Open.Database.Extensions.Tests; -// The mapped queries open their readers with CommandBehavior.SequentialAccess, where a provider (SqlClient, for one) only lets a row's cells be read in ascending ordinal order. +// With SequentialAccess() the mapped queries open their readers with CommandBehavior.SequentialAccess, where a provider (SqlClient, for one) only lets a row's cells be read in ascending ordinal order. // The row readers the mapping core compiles must therefore read the cells of a row in column order, whatever order the model declares its properties in, and whatever path // (typed getter, or the boxed general conversion) each cell takes. Constructor binding builds the object after reading its arguments, and depends on this being // the existing behavior; these tests pin it, for a model built as ever and for a model built through its constructor. diff --git a/Tests/Open.Database.Extensions.Core.Tests/SingleResultBeforeMapTests.cs b/Tests/Open.Database.Extensions.Core.Tests/SingleResultBeforeMapTests.cs index 4b147bf6..dafb918e 100644 --- a/Tests/Open.Database.Extensions.Core.Tests/SingleResultBeforeMapTests.cs +++ b/Tests/Open.Database.Extensions.Core.Tests/SingleResultBeforeMapTests.cs @@ -24,7 +24,7 @@ sealed record IdName(int Id, string? Name); const int LaterSets = 2; - const CommandBehavior Generated = CommandBehavior.SingleResult | CommandBehavior.SequentialAccess; + const CommandBehavior Generated = CommandBehavior.SingleResult; static FakeExecuteReader Expressive(int rows, out Func reader, int? failAt = null) { @@ -456,7 +456,7 @@ public static void EveryMapOverload_AfterSingleResult_OnARawCommand_ReturnsAMapp } [Fact] - public static void AGeneratedMapping_KeepsSequentialAccess_AndASelectorDoesNot() + public static void AGeneratedMapping_AndASelector_AskForTheSameFlags() { FakeExecuteReader command = Expressive(2, out _); @@ -548,7 +548,7 @@ public static void TheCommandItself_StillReadsThrough_AfterAnOptedOutQuery() single.Map().ToList(); Assert.Equal(0, reader().NextResultCalls); - Assert.Equal([Generated, CommandBehavior.SequentialAccess, Generated], command.Behaviors); + Assert.Equal([Generated, CommandBehavior.Default, Generated], command.Behaviors); } [Fact] diff --git a/docsite/articles/async-reads.md b/docsite/articles/async-reads.md index 5374ef07..b68c6d28 100644 --- a/docsite/articles/async-reads.md +++ b/docsite/articles/async-reads.md @@ -44,7 +44,7 @@ The figure has no numbers. It shows the two lanes described above. Three things were measured: CPU, memory, and wall time over a real link. Each has a benchmark page with the chart, the numbers and how they were made. - **CPU.** The synchronous read costs less. With nothing waiting, `ReadAsync()` for every row cost 4.8% more than the fully synchronous read (80.0 against 76.3 µs for 1,000 rows of 20 columns). [Sync reads against async reads](benchmarks/sync-vs-async.md). -- **Memory.** On `Map(Func)` over SQL Server, the default allocated about 42% less (9,713 against 16,812 KB). `Map()` was equal. [Slow links and large values](benchmarks/slow-links-and-large-values.md#memory). +- **Memory.** On `Map(Func)` over SQL Server, the default allocated about 42% less (9,713 against 16,812 KB). `Map()`, measured with `SequentialAccess()`, was equal. [Slow links and large values](benchmarks/slow-links-and-large-values.md#memory). - **Wall time on a real link.** The same: over a 5 ms, 100 Mbit link the link sets the time, and every read path took 537 to 541 ms for 10,000 rows. [Slow links and large values](benchmarks/slow-links-and-large-values.md#time-over-the-link). ## AsyncReads(): why it exists @@ -83,7 +83,7 @@ On `Map(Func)`, +73% memory at equal time: 9,713 KB against 16,812 KB, and 538.3 [!code-csharp[](../samples/AsyncReads.cs#asyncreads_func)] -On `Map()`, equal memory (219.2 against 219.1 KB per 1,000 rows). CPU, with nothing waiting, is +3.4% against the default at width 20 (80.0 against 77.4 µs per 1,000 rows), on a synthetic provider where every `ReadAsync` completes at once. See [Slow links and large values](benchmarks/slow-links-and-large-values.md) and [Sync reads against async reads](benchmarks/sync-vs-async.md). +On `Map()`, measured with `SequentialAccess()`, equal memory (219.2 against 219.1 KB per 1,000 rows). CPU, with nothing waiting, is +3.4% against the default at width 20 (80.0 against 77.4 µs per 1,000 rows), on a synthetic provider where every `ReadAsync` completes at once. See [Slow links and large values](benchmarks/slow-links-and-large-values.md) and [Sync reads against async reads](benchmarks/sync-vs-async.md). ### The busy-pool hazard @@ -91,9 +91,9 @@ Measured, synthetic, `Map()` shape: with a read wait every 100 rows (20 µs) On a real link it is UNMEASURED. -### The large-value warning for Map(Func) +### The large-value warning -One value of 100 MB (one row, SQL Server, over a simulated slow link) took 8.86 s with a raw sync `Read` and 48.0 s with raw `Default` and `ReadAsync`: 5.4 times as long. `Map()` with the opt-in took 8.86 s, and it opens its reader with `SequentialAccess`, as the raw 8.86 s cell does. `Map(Func)` opens its reader with `Default`, so the 48.0 s cell is the one that applies to it; ODX `Map(Func)` with the opt-in on a 100 MB value was NOT measured, and its cost is inferred from the raw cell. The chart and the table are on [Slow links and large values](benchmarks/slow-links-and-large-values.md#one-100-mb-value). +One value of 100 MB (one row, SQL Server, over a simulated slow link) took 8.86 s with a raw sync `Read` and 48.0 s with raw `Default` and `ReadAsync`: 5.4 times as long. `Map()` with `AsyncReads()` and sequential access took 8.86 s, as the raw `SequentialAccess` cell did. Every map reads with the default access mode, so with `AsyncReads()` on a very large value, add [`SequentialAccess()`](expressive-commands.md#sequential-access-for-very-large-values); without it the 48.0 s cell is the one that applies. ODX with `AsyncReads()` and default access on a 100 MB value was NOT measured: its cost is inferred from the raw cell. The chart and the table are on [Slow links and large values](benchmarks/slow-links-and-large-values.md#one-100-mb-value). The default, a synchronous `Read`, is the safe choice for large values. @@ -101,4 +101,4 @@ The default, a synchronous `Read`, is the safe choice for large values. Every number on this page is on a benchmark page, with its chart, its table, and how it was made: [Sync reads against async reads](benchmarks/sync-vs-async.md) (the model) and [Slow links and large values](benchmarks/slow-links-and-large-values.md) (SQL Server over a simulated link). -Two claims here are not measurements. Which reader behavior each map uses (`Map()`: `SequentialAccess`; `Map(Func)`: `Default`, and each adds `SingleResult` after `.SingleResult()`) comes from the library source. That an async terminal calls `Read` and not `ReadAsync` by default, and the reverse after `AsyncReads()`, is pinned by `AsyncReadsTests` in the Core tests. +Two claims here are not measurements. Which reader behavior each map uses (`Default`, adding `SingleResult` after `.SingleResult()` and `SequentialAccess` after `.SequentialAccess()`) comes from the library source. That an async terminal calls `Read` and not `ReadAsync` by default, and the reverse after `AsyncReads()`, is pinned by `AsyncReadsTests` in the Core tests. diff --git a/docsite/articles/benchmarks/slow-links-and-large-values.md b/docsite/articles/benchmarks/slow-links-and-large-values.md index cfe72cb3..bc0b0ccf 100644 --- a/docsite/articles/benchmarks/slow-links-and-large-values.md +++ b/docsite/articles/benchmarks/slow-links-and-large-values.md @@ -2,14 +2,14 @@ **The question:** the [sync against async](sync-vs-async.md) page uses a model. What happens on a real SQL Server over a slow link, and with one very large value? -All the numbers here are from a hand-run probe on SQL Server in a container, behind a simulated link (5 ms delay, 100 Mbit). Each case is one launch: one warm-up, then the mean of 3 measured operations (one for the large value). +All the numbers here are from a hand-run probe on SQL Server in a container, behind a simulated link (5 ms delay, 100 Mbit). Each case is one launch: one warm-up, then the mean of 3 measured operations (one for the large value). `Map()` in these runs read with [`SequentialAccess()`](../expressive-commands.md#sequential-access-for-very-large-values). ## In short - **The link sets the time, not the read.** Over the simulated link, 10,000 rows of 20 columns took 537.5 ms with ODX's sync read and 540.7 ms with a raw `ReadAsync()`, and 538.2 to 538.3 ms in the memory run with and without `AsyncReads()`. With an 8,000-byte column they took about 6.76 s either way. The read path did not change the wall time. - **The sync read allocates less, sometimes much less.** With `Map(Func)` (`Map` with a selector function you write, the hand-written selector of the other pages), `AsyncReads()` allocated **16,812 KB** against **9,713 KB** (+73.1%) for the same rows in the same time. With `Map()` the two were equal (9,743 against 9,709 KB, +0.35%). -- **One 100 MB value is the dangerous case.** Raw SqlClient with `Default` (the normal mode, which reads a whole row into memory first) and `ReadAsync` took **48.0 s**, against **8.86 s** with a sync `Read()` (5.4 times as long). `Map()` with `AsyncReads()` took 8.86 s too. It opens its reader with `SequentialAccess` (which streams a value), as the raw 8.86 s cell does; we did not isolate that as the reason. -- **Not measured:** `Map(Func)` with `AsyncReads()` on a 100 MB value. It opens its reader with `Default`, so the 48.0 s cell is the one that would apply. That is an inference from the raw cell, not a measurement. +- **One 100 MB value is the dangerous case.** Raw SqlClient with `Default` (the normal mode, which reads a whole row into memory first) and `ReadAsync` took **48.0 s**, against **8.86 s** with a sync `Read()` (5.4 times as long). `Map()` with `AsyncReads()` and sequential access (which streams a value, as the raw 8.86 s cell does) took 8.86 s too; we did not isolate that as the reason. Sequential access is [opt-in](../expressive-commands.md#sequential-access-for-very-large-values): call `SequentialAccess()`. +- **Not measured:** ODX with `AsyncReads()` and default access on a 100 MB value. Every map reads with `Default` unless you call `SequentialAccess()`, so the 48.0 s cell is the one that would apply. That is an inference from the raw cell, not a measurement. - **Not faster:** `AsyncReads()` took the same wall time as the sync read (538.2 against 538.3 ms), and gained nothing in the runs. ## Time over the link @@ -34,11 +34,11 @@ On `Map(Func)` with `AsyncReads()`, about 7.9% of the `ReadAsync` calls (on aver ## One 100 MB value -
Horizontal bars in seconds for one 100 MB value. Raw sync Read 8.86; raw Default with ReadAsync 48.0; raw SequentialAccess with ReadAsync 8.86; ODX Map of T with AsyncReads 8.86; raw Default with ReadAsync and both SqlClient switches off 8.87; ODX Map of Func with AsyncReads not measured.
+
Horizontal bars in seconds for one 100 MB value. Raw sync Read 8.86; raw Default with ReadAsync 48.0; raw SequentialAccess with ReadAsync 8.86; ODX Map of T with AsyncReads and sequential access 8.86; raw Default with ReadAsync and both SqlClient switches off 8.87; ODX with AsyncReads and default access not measured.
-How long one row holding one 100 MB value takes. One bar is far longer than the rest: the raw `Default` read with `ReadAsync`. The others, including ODX `Map()` with `AsyncReads()`, take about the same time as a sync read. The size is in the [source of the data](../../perf-data/large-value.source.txt): one `varbinary(max)` value of 100 MB. +How long one row holding one 100 MB value takes. One bar is far longer than the rest: the raw `Default` read with `ReadAsync`. The others, including ODX `Map()` with `AsyncReads()` and sequential access, take about the same time as a sync read. The size is in the [source of the data](../../perf-data/large-value.source.txt): one `varbinary(max)` value of 100 MB. -`Map(Func)` with `AsyncReads()` on this value was not measured. On the 10,000 rows of the [memory run](#memory) (not a large value) it allocated more with `AsyncReads()` than with the sync read: 16,812 against 9,713 KB. +ODX with `AsyncReads()` and default access on this value was not measured. On the 10,000 rows of the [memory run](#memory) (not a large value) `Map(Func)` allocated more with `AsyncReads()` than with the sync read: 16,812 against 9,713 KB. [!include[](../../includes/perf/large-value.md)] diff --git a/docsite/articles/expressive-commands.md b/docsite/articles/expressive-commands.md index fc07bce0..753999bf 100644 --- a/docsite/articles/expressive-commands.md +++ b/docsite/articles/expressive-commands.md @@ -203,6 +203,17 @@ The `Async` terminals honor the command's cancellation token (`UseCancellationTo `UseCancellationToken(token)` sets a token for the command. A token passed to an async terminal such as `ToListAsync(token)` is combined with it, and either one cancels the call. The `Async` terminals of the command itself (`ExecuteNonQueryAsync`, `ExecuteScalarAsync`, `ExecuteReaderAsync`, `ExecuteReturnAsync`) take a `CancellationToken` too, and it is combined with this one. The call then stops with `OperationCanceledException`, except that a provider may report a cancellation that arrives while the command is executing as its own exception (SQL Server's `SqlException`, "Operation cancelled by user"); the library does not translate it. The token covers opening the connection, looking up stored-procedure parameter names, executing the command and reading the rows. +### Sequential access, for very large values + +The library reads with the default access mode, in which SqlClient reads a whole row into memory before your code reads it. `SequentialAccess()` asks for `CommandBehavior.SequentialAccess` instead: the provider streams the row, and each column can be read once, in ascending order. Use it for very large text or binary values, above all one value copied as a stream: + +[!code-csharp[](../samples/ExpressiveCommands.cs#sequential_stream)] + +- On a command, it applies to every reader the command opens: a reader callback, the `Map` terminals and `LoadTable`. +- It is also on every mapped view and definition: `command.Map().SequentialAccess()`. +- A selector given to `Map` must read the columns in ascending order, or the provider throws. `Map()`, `AsObjectArrays()` and `AsDictionaryRows()` read in column order, so they work with it. +- With [`AsyncReads()`](async-reads.md) and a very large value, opt in: without it, SqlClient read one 100 MB value [far more slowly](benchmarks/slow-links-and-large-values.md#one-100-mb-value) with `ReadAsync`. + ### Which scalar form - **`ExecuteScalarAsync()`** for the value as `T`; it converts the way `Map()` does (a `bigint` read as `int`). No rows and a `NULL` are both `null` for a type that takes null (`int?`, `string`), and both throw `ValueMappingException` for a non-nullable value type, so ask for `int?` and give the default yourself: `(await command.ExecuteScalarAsync(token)) ?? -1`. diff --git a/docsite/articles/mapping.md b/docsite/articles/mapping.md index bdb66353..b0fe50e9 100644 --- a/docsite/articles/mapping.md +++ b/docsite/articles/mapping.md @@ -417,7 +417,7 @@ When there is no model class, ask for the rows as they are. `AsObjectArrays()` g [!code-csharp[](../samples/Migration.cs#migration_mappeddictionaries_after)] -Both are mapped views like `Map()`: the same terminals, `Skip` and `Take`, `SingleResult()`, `AsyncReads()` and `UsePool(pool, clearOnReturn)`, and, on a command or a query, the same read through the later result sets. They exist on an expressive command, an `IDbCommand`, a reader you own, a `DataTable` and a `DbQuery` definition. Every column is read once, in order, so a provider can stream the row. The buffers that hold the rows (the chunk arrays) are pooled and are cleared when they go back, whatever `clearOnReturn` says; each row array is yours. +Both are mapped views like `Map()`: the same terminals, `Skip` and `Take`, `SingleResult()`, `AsyncReads()`, `SequentialAccess()` and `UsePool(pool, clearOnReturn)`, and, on a command or a query, the same read through the later result sets. They exist on an expressive command, an `IDbCommand`, a reader you own, a `DataTable` and a `DbQuery` definition. Every column is read once, in order, so they also work with [`SequentialAccess()`](expressive-commands.md#sequential-access-for-very-large-values). The buffers that hold the rows (the chunk arrays) are pooled and are cleared when they go back, whatever `clearOnReturn` says; each row array is yours. A `DictionaryRow` is a `struct` over the row's values and one list of column names that every row of the result set shares. Its dictionary side covers the distinct names (the first column with a name wins; a name is found exactly, else ignoring case; a missing name throws `KeyNotFoundException`); the ordinal indexer and `FieldCount` reach every column. `ToDictionary()` makes a copy you own. Handing the row to an `IReadOnlyDictionary` boxes it. A result with no rows has no names. It is not a model: `Map()` throws and points here. To keep only some columns, select just those in the query; the column names of a result with no rows come from the reader you own (`GetSchemaTable`, or `GetName` for each of `FieldCount`). diff --git a/docsite/articles/performance.md b/docsite/articles/performance.md index 5b9604cf..0604a947 100644 --- a/docsite/articles/performance.md +++ b/docsite/articles/performance.md @@ -1,6 +1,9 @@ # Benchmarks ODX is built on one idea: hold the connection open for as short a time as possible, and allocate as little as possible while it is open. + +The `Map()` figures on these pages were measured with [`SequentialAccess()`](expressive-commands.md#sequential-access-for-very-large-values). + ## In short - **With no database in the way**, `Map()` holds the connection open for **2.6 times less time** than Dapper (76.1 against 199.9 µs) and allocates **2.4 times less memory** (227.4 against 548.1 KB). 20 columns, 1,000 rows, synthetic reader. diff --git a/docsite/articles/release-notes.md b/docsite/articles/release-notes.md index 885cdc5a..6e029427 100644 --- a/docsite/articles/release-notes.md +++ b/docsite/articles/release-notes.md @@ -6,6 +6,7 @@ Version 11 is `11.0.0-rc.15`. For moving a 10.x codebase, read [Coming from earl ### Changes since rc.15 +- **Changed: sequential access is opt-in.** The library reads with the default access mode on every path; it no longer asks for `CommandBehavior.SequentialAccess` itself, as `Map()`, `AsObjectArrays()`, `AsDictionaryRows()`, `AnyAsync`, `CountAsync` and `LoadTable`/`LoadTables` did, and the default `behavior` of `ToDataTable` and `ToDataTables` on an `IDbCommand` is now `CommandBehavior.Default`. SqlClient's default mode reads each row whole before your code reads it. Call `SequentialAccess()` on a command, a mapped view or a definition to opt in, above all for very large values; with `AsyncReads()` on such a value, opt in. See [Sequential access](expressive-commands.md#sequential-access-for-very-large-values). - **New: generated row readers, on by default.** The Core 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()` on a command or a reader gets its row reader written at build time. A model that declares every column's ordinal is read by position, unchecked. `false` switches it off. See [Generated readers](mapping.md#generated-readers). - **Stored-procedure parameter names are read once and kept, an answer of no names included.** A call that cannot be built, or that the database rejects, forgets them and the next call reads them again. The five-minute expiry is gone, and an argument the kept names lack no longer reads them again before the call. See [Parameter names are read once](expressive-commands.md#parameter-names-are-read-once). - **Loop over a pooled buffer while it reads.** `AsAsyncEnumerable()` on what `ToPooledBuffer` returns gives its rows as a stream while the query is still running; each loop starts at the first row, and the rows can be looped over again until the buffer is disposed. Rows arrive an array at a time (16 rows, then 32, and so on). `Items` is unchanged. See [looping over the buffer](async-buffers.md#looping-over-the-buffer). diff --git a/docsite/images/perf/perf-large-value.svg b/docsite/images/perf/perf-large-value.svg index a75b1cdc..243c04fe 100644 --- a/docsite/images/perf/perf-large-value.svg +++ b/docsite/images/perf/perf-large-value.svg @@ -1,6 +1,6 @@ One 100 MB value over a slow link - Horizontal bars in seconds for one 100 MB value over a simulated 5 ms, 100 Mbit link, SQL Server. Every bar starts at zero. Raw, Default, sync Read 8.86; Raw, Default, ReadAsync 48.02; Raw, SequentialAccess, ReadAsync 8.86; Raw, Default, ReadAsync, switches off 8.87; ODX Map<T>(), AsyncReads() 8.86. ODX Map(Func) with AsyncReads() was not measured. Every bar starts at zero. Raw, Default, sync Read 8.86 s; Raw, Default, ReadAsync 48.02 s; Raw, SequentialAccess, ReadAsync 8.86 s; Raw, Default, ReadAsync, switches off 8.87 s; ODX Map<T>(), AsyncReads() 8.86 s. + Horizontal bars in seconds for one 100 MB value over a simulated 5 ms, 100 Mbit link, SQL Server. Every bar starts at zero. Raw, Default, sync Read 8.86; Raw, Default, ReadAsync 48.02; Raw, SequentialAccess, ReadAsync 8.86; Raw, Default, ReadAsync, switches off 8.87; ODX Map<T>(), AsyncReads(), SequentialAccess 8.86. ODX with AsyncReads() and default access was not measured. Every bar starts at zero. Raw, Default, sync Read 8.86 s; Raw, Default, ReadAsync 48.02 s; Raw, SequentialAccess, ReadAsync 8.86 s; Raw, Default, ReadAsync, switches off 8.87 s; ODX Map<T>(), AsyncReads(), SequentialAccess 8.86 s. diff --git a/docsite/includes/perf/large-value.md b/docsite/includes/perf/large-value.md index 8f99b294..43061d86 100644 --- a/docsite/includes/perf/large-value.md +++ b/docsite/includes/perf/large-value.md @@ -6,5 +6,5 @@ | Raw SqlClient, Default, ReadAsync | 48.02 | 5.42× | 369.5 | | Raw SqlClient, SequentialAccess, ReadAsync | 8.86 | 1.00× | not recorded | | Raw SqlClient, Default, ReadAsync, both SqlClient switches off | 8.87 | 1.00× | 383.7 | -| ODX Map<T>(), AsyncReads() | 8.86 | 1.00× | not recorded | -| ODX Map(Func), AsyncReads() | not measured | not measured | not measured | +| ODX Map<T>(), AsyncReads(), SequentialAccess | 8.86 | 1.00× | not recorded | +| ODX Map<T>() or Map(Func), AsyncReads(), Default | not measured | not measured | not measured | diff --git a/docsite/perf-data/large-value.csv b/docsite/perf-data/large-value.csv index 4bb7c2db..2a41c930 100644 --- a/docsite/perf-data/large-value.csv +++ b/docsite/perf-data/large-value.csv @@ -3,5 +3,5 @@ variant,family,seconds,peak_working_set_mb,note,source_run "Raw SqlClient, Default, ReadAsync",raw,48.015,369.5,,s4 "Raw SqlClient, SequentialAccess, ReadAsync",raw,8.861,,,s4 "Raw SqlClient, Default, ReadAsync, both SqlClient switches off",raw,8.873,383.7,,s4-switches -"ODX Map(), AsyncReads()",rd-async,8.862,,"Map() opens its reader with SequentialAccess",s4 -"ODX Map(Func), AsyncReads()",rd-async,,,"Not measured. Map(Func) opens its reader with Default, so the raw Default and ReadAsync cell is the one that applies to it.", +"ODX Map(), AsyncReads(), SequentialAccess",rd-async,8.862,,"Measured with SequentialAccess().",s4 +"ODX Map() or Map(Func), AsyncReads(), Default",rd-async,,,"Not measured. Without SequentialAccess() every map opens its reader with Default, so the raw Default and ReadAsync cell is the one that applies.", diff --git a/docsite/samples/ExpressiveCommands.cs b/docsite/samples/ExpressiveCommands.cs index 9d1d5055..5cb56f19 100644 --- a/docsite/samples/ExpressiveCommands.cs +++ b/docsite/samples/ExpressiveCommands.cs @@ -221,4 +221,28 @@ await connection return (closedBefore, closedAfter, openBefore, openAfter); } + + public static async Task CopyBodyAsync( + IDbConnectionFactory connectionFactory, + int id, + MemoryStream destination, + CancellationToken cancellationToken) + { + #region sequential_stream + // One large value, copied as a stream: ask for sequential access, + // select the large column last, and read the columns in order. + await connectionFactory + .Command("select id, body from posts where id = @id") + .AddParam(id) + .SequentialAccess() + .ExecuteReaderAsync(async ValueTask (reader) => + { + if (!await reader.ReadAsync(cancellationToken)) return; + await using Stream body = reader.GetStream(1); + await body.CopyToAsync(destination, cancellationToken); + }, cancellationToken: cancellationToken); + #endregion + + return destination.Length; + } } diff --git a/docsite/samples/Program.cs b/docsite/samples/Program.cs index 8e4c317e..69b1417c 100644 --- a/docsite/samples/Program.cs +++ b/docsite/samples/Program.cs @@ -42,6 +42,12 @@ void Check(bool condition, string what) Check(closedBefore == ConnectionState.Closed && closedAfter == ConnectionState.Closed, "a closed connection is closed again after the call"); Check(openBefore == ConnectionState.Open && openAfter == ConnectionState.Open, "an open connection stays open"); +using (var copy = new MemoryStream()) +{ + long copied = await ExpressiveCommands.CopyBodyAsync(factory, 1, copy, CancellationToken.None); + Check(copied == 6 && System.Text.Encoding.UTF8.GetString(copy.ToArray()) == "Body 1", "a value read as a stream with SequentialAccess()"); +} + (long count, int updated) = await ExpressiveCommands.ScalarAndNonQueryAsync(factory, CancellationToken.None); Check(count == 3 && updated == 3, "scalar and non-query"); Check(await ExpressiveCommands.ConvertedScalarAsync(factory, CancellationToken.None) == 5, "ExecuteScalar with a conversion"); diff --git a/docsite/tools/perf/New-PerfCharts.ps1 b/docsite/tools/perf/New-PerfCharts.ps1 index d88c530e..dfa3afa0 100644 --- a/docsite/tools/perf/New-PerfCharts.ps1 +++ b/docsite/tools/perf/New-PerfCharts.ps1 @@ -387,8 +387,8 @@ Write-Lf (Join-Path $ImageDir 'perf-link-memory.svg') (New-BarSvg 'link-memory' $lvRows = @($lv | Where-Object { $_.seconds } | ForEach-Object { [pscustomobject]@{ Name = ($_.variant -replace 'Raw SqlClient, ', 'Raw, ' -replace 'both SqlClient switches off', 'switches off'); Fam = $_.family; Value = [double]$_.seconds Detail = "$($_.variant): $(F ([double]$_.seconds) 2) s for one 100 MB value$(if ($_.peak_working_set_mb) { ", peak working set $($_.peak_working_set_mb) MB" })." } }) -$lvDesc = 'Horizontal bars in seconds for one 100 MB value over a simulated 5 ms, 100 Mbit link, SQL Server. Every bar starts at zero. ' + (($lvRows | ForEach-Object { "$($_.Name) $(F $_.Value 2)" }) -join '; ') + '. ODX Map(Func) with AsyncReads() was not measured.' -Write-Lf (Join-Path $ImageDir 'perf-large-value.svg') (New-BarSvg 'large-value' 'One 100 MB value over a slow link' 'Shorter is better. SQL Server, 5 ms delay, 100 Mbit link.' @(@{ Title = ''; Rows = $lvRows }) { param($v) (F $v 2) + ' s' } 'seconds for one operation' ("ODX Map(Func) with AsyncReads() was not measured.|" + (Link-Footer $lvSrc 'large-value')) 'shared' 262 $lvDesc 560) +$lvDesc = 'Horizontal bars in seconds for one 100 MB value over a simulated 5 ms, 100 Mbit link, SQL Server. Every bar starts at zero. ' + (($lvRows | ForEach-Object { "$($_.Name) $(F $_.Value 2)" }) -join '; ') + '. ODX with AsyncReads() and default access was not measured.' +Write-Lf (Join-Path $ImageDir 'perf-large-value.svg') (New-BarSvg 'large-value' 'One 100 MB value over a slow link' 'Shorter is better. SQL Server, 5 ms delay, 100 Mbit link.' @(@{ Title = ''; Rows = $lvRows }) { param($v) (F $v 2) + ' s' } 'seconds for one operation' ("ODX with AsyncReads() and default access was not measured.|" + (Link-Footer $lvSrc 'large-value')) 'shared' 262 $lvDesc 560) # ---------- 8. channels and dataflow (hand-copied from Benchmarks/RESULTS.md) ---------- $ch = Read-Data 'channels'; $chSrc = Read-Source 'channels'