Skip to content

Resolve the table path once and suppress the finalizer on Close - #342

Merged
chrisrichards merged 1 commit into
mainfrom
resolve-path-once
Nov 23, 2026
Merged

chrisrichards merged 1 commit into
mainfrom
resolve-path-once

Conversation

@chrisrichards

Copy link
Copy Markdown
Member

Why

The cross-library benchmark shows Sylvan about 19% ahead of DbfDataReader (280 us vs 351 us). That gap is not in the read path: the benchmark opens the fixture by relative path, and DbfTable(string path) resolved the current directory six times per open (File.Exists, the FileStream open, and four memo-file File.Exists checks). Each lookup costs about 10 us on macOS. Sylvan is handed a stream from a single File.OpenRead.

BenchmarkDotNet (short job, 2.3.1 package, .NET 10.0.15, M3 Max):

Fixture path Sylvan DbfData
Relative (as the repo benchmark) 280 us 355 us
Absolute 256 us 255 us
Relative, resolved once before the constructor - 286 us

Changes

  • DbfTable(string path) calls Path.GetFullPath once and uses the result for the existence check, the FileStream and the memo lookup. The Path property and MemoPath() return the same values as before.
  • DbfTable.Close() calls Dispose() instead of Dispose(true), so the finalizer is suppressed. Previously every closed table was still finalized and promoted, which is why the benchmark showed Gen1 9.8 / Gen2 0.5 collections per 1000 operations against Sylvan's 1.0 / 0.

Measured

Stopwatch harness against this branch (not BenchmarkDotNet):

Before After
Open, relative path 87 us 31 us
Open, absolute path 22 us 20 us
Gen1 collections per 1000 ops 5.8 1.6
Gen2 collections per 1000 ops 0.2 0

The saving is a fixed cost per open, so it matters for small tables and is negligible for large ones.

The repo benchmark has not been re-run against this change: it reads the published package, so that needs a release or a local pack.

Testing

dotnet test -c Release: 535 passed, 1 skipped (already skipped on main).

🤖 Generated with Claude Code

Opening a table by relative path resolved the current directory six
times (File.Exists, the FileStream open and four memo-file checks).
Each lookup costs about 10 us on macOS, which made opening a small
table by relative path far slower than by absolute path. The path is
now resolved once and reused.

DbfTable.Close called Dispose(true) directly, so the finalizer was
never suppressed and every closed table was promoted to the next GC
generation. Close now goes through Dispose().

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@chrisrichards
chrisrichards merged commit 8cd7308 into main Nov 23, 2026
3 checks passed
@chrisrichards
chrisrichards deleted the resolve-path-once branch November 23, 2026 14:56
chrisrichards added a commit that referenced this pull request Nov 23, 2026
…#343)

Since #342 the table path is resolved with Path.GetFullPath before the
existence check, so a null path throws ArgumentNullException and an
empty path or one containing a NUL character throws ArgumentException.
Previously all three were reported as FileNotFoundException. The new
exceptions match File.OpenRead and FileStream and describe the problem
better, so the tests now state them as the intended behaviour. A path
to a file that does not exist still throws FileNotFoundException.

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant