Repository navigation
Skip unnecessary literal scans on .NET Framework - #2283
Open
tuncaypeker wants to merge 1 commit into
Open
tuncaypeker wants to merge 1 commit into
tuncaypeker wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
Related to #1484.
GetLiteralTokens runs the .NET Framework compiled regex over every command, even when it cannot contain a literal token. Use IndexOf('{') to reject brace-free commands and pass the first brace's index to both regex calls, avoiding another scan over the same prefix when tokens are present. The regex still enforces the existing token syntax, Unicode rules, and preceding-character boundary.
This optimization is limited to the .NET Framework build. The netstandard2.0 and modern .NET implementations keep their existing parsing path. No public API, settings, or dependencies are added.
Validation:
Benchmark:
BenchmarkDotNet 0.15.8, net481 executable, .NET Framework host 4.8.10008.0, x64 RyuJIT, Intel Core i7-1360P, Windows 11. InProcessEmit toolchain, one launch, three warmups, ten measured iterations of 250 ms. The unchanged upstream parser and candidate Release parser are loaded into separate assembly contexts in the same process and invoked through equivalent cached delegates. A setup check rejects accidental assembly unification. These are synthetic parser microbenchmarks with 10,000 characters of padding, not end-to-end database timings.
The early-token measurements have overlapping error intervals (before +/-13.639 us, after +/-16.179 us); no speedup is claimed for that case. The primary benefit is avoiding the .NET Framework regex's character-by-character scan over a long prefix. Modern .NET and netstandard2.0 retain their original code path.
Standalone benchmark reproduction
Build and save separate net461 Release DLLs before and after the change. Set DAPPER_BENCH_BASELINE and DAPPER_BENCH_CANDIDATE to their absolute paths. Create the following bench.csproj and Program.cs outside the repository, build in Release, and run the resulting net481 executable with --filter '*'. This harness needs no database.