Add asynchronous record reading - #284
Merged
Merged
Conversation
Adds true async I/O to the read path. Each record is fetched with a single buffered Stream.ReadAsync into the existing reused record buffer and then parsed synchronously from memory by the existing span-based value readers, shared with the synchronous path via ParseRecord. New API: DbfRecord.ReadAsync(Stream, CancellationToken), DbfTable.ReadAsync(DbfRecord, CancellationToken), DbfTable.ReadRecordAsync(CancellationToken), and a real DbfDataReader.ReadAsync(CancellationToken) override (previously the inherited DbDataReader default wrapped the synchronous Read). ValueTask-based internals avoid per-record task allocations when reads complete synchronously from the FileStream buffer, and the cancellation token flows through to the underlying stream. Memo values are still resolved synchronously while parsing; memo blocks are small seeked reads and can be made async separately if needed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
This was referenced Jul 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Adds true async I/O to the read path — until now
DbfDataReaderinheritedDbDataReader's defaultReadAsync, which just wraps the synchronousRead()in a completed task.Design: one buffered async read per record, synchronous parsing.
DbfRecord.ReadAsyncfills the existing reused record buffer withStream.ReadAsync(Memory<byte>, CancellationToken)(same partial-read loop as the sync path), then parses via the existing span-based value readers. The parse is shared with the sync path through a privateParseRecord(spans can't live in async methods, which makes the split natural). This is deliberately the opposite of the 2018 fork's approach (per-field async through a hand-ported asyncBinaryReader) — one awaited read per record instead of one per field, and a single code path for all value parsing.New API:
DbfRecord.ReadAsync(Stream, CancellationToken)→ValueTask<bool>DbfTable.ReadAsync(DbfRecord, CancellationToken)→ValueTask<bool>DbfTable.ReadRecordAsync(CancellationToken)→ValueTask<DbfRecord>DbfDataReader.ReadAsync(CancellationToken)— real override with the same skip-deleted loop asRead()ValueTaskinternals mean no per-record task allocation when reads complete synchronously from theFileStreambuffer (the common case); theTask<bool>-returning override benefits from the cached true/false task optimisation. Cancellation flows through to the underlying stream.EndOfStreamExceptionhandling matches the sync path.Scope notes:
FileOptions.Asynchronousby default — with one buffered read per record the handle mode matters little, and it would slow the dominant sync path; callers wanting a fully async handle can pass their ownFileStreamvia the stream constructors).OpenAsyncfor header/columns),IAsyncEnumerable<DbfRecord>.Test plan
New
AsyncReadTests(7 tests): full-table async read compared row-by-row against the sync path (dbase_03, and dbase_30 to cover memo resolution inside async reads),RecordIndextracking,Seek+ReadAsync,ReadRecordAsync, skip-deleted through the reader override (12 of 14 rows), and cancellation (pre-cancelled token throwsOperationCanceledException). The existingDbfDbConnectiontests already callExecuteReaderAsync/ReadAsyncand now exercise the real override. Full suite: 119 passed, 1 skipped (pre-existing WIP skip).🤖 Generated with Claude Code