Skip to content

Parse numeric fields straight from the record bytes on .NET 8+ - #340

Merged
chrisrichards merged 1 commit into
mainfrom
parse-numbers-from-bytes
Nov 23, 2026
Merged

chrisrichards merged 1 commit into
mainfrom
parse-numbers-from-bytes

Conversation

@chrisrichards

Copy link
Copy Markdown
Member

AsciiFieldParser copied each numeric field into a stack-allocated char span and then parsed that. .NET 8 and later have TryParse overloads that take UTF-8 bytes, so on the net10.0 target the int, long, decimal and float parsers now parse the record bytes directly. netstandard2.1 keeps the existing copy-then-parse path behind #if, as the byte overloads do not exist there. Date parsing is unchanged.

Behaviour

No change intended. Two checks:

  • The existing parity tests in DbfValueParsingTests pass, including Numeric_bytes_above_ascii_fail_to_parse_like_ascii_decoding_did.
  • A fuzz comparison of the old and new paths over 3 million random fields (12 million comparisons across the four types; inputs mixing digits, spaces, signs, ., E, NUL, tab, *, ,, letters and bytes above 0x7f) found no difference in either the success flag or the parsed value. The fuzz script is not part of this PR.

Measurements

A modest win, proportional to how numeric the table is.

Per field (Release, Apple M3 Max, best of 7 runs of 5 million parses):

Field Before After
N(14,0) → long 13.9 ns 8.8 ns
N(14,4) → decimal 48.7 ns 44.2 ns

On the cross-library benchmark fixture (tl_2019_01_place.dbf), which has only 2 numeric columns out of 16, the read loop goes from about 272 µs to 266 µs — close to measurement noise. Tables dominated by integer columns benefit most.

Testing

Full suite: 535 passed, 1 skipped (pre-existing).

🤖 Generated with Claude Code

AsciiFieldParser copied each numeric field into a stack-allocated char
span before parsing. .NET 8 and later can parse the bytes directly, so
skip the copy there. netstandard2.1 keeps the existing path.

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

Copy link
Copy Markdown

@chrisrichards
chrisrichards merged commit 7fc590f into main Nov 23, 2026
3 checks passed
@chrisrichards
chrisrichards deleted the parse-numbers-from-bytes branch November 23, 2026 13:35
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