Repository navigation
Conversation
Short Ratio and score-only PartialRatio use stack-backed character masks. Long patterns use a direct char LCS kernel (register state for one and two words, branch-free carry) with per-thread clean pattern tables and an open-addressed index for non-Latin-1 symbols, replacing a dictionary and an interface call per symbol. PartialRatio skips prefix/suffix scans that the exact outer-window scores prove cannot win, exits early for disjoint alphabets, and keeps its window queue in the pooled scores buffer. WeightedRatio gains exact upper-bound exits and shared token preparation, with span-based token sets on .NET 6+. Scores, alignment tie order and the generic API are unchanged; the 388-pair matrix matches 6.0.3 exactly. Each short stack table is zeroed once: a second clear measured unstable and up to 15% slower. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
The window queue lived in the scores rental for every input (five ints per window), so a 65-unit pattern against a 1,000,065-unit text allocated 33,563,888 B on a cold pool against 4,208,712 B for 6.0.3. Up to 256 windows the queue still shares that rental; above it a separate queue grows between breadth-first levels with the windows actually queued (4,204,040 B for the same input). Growth stays out of the window loop and the method's locals are kept minimal: one more local stopped the JIT inlining it, which cost about 30 ns on 8-unit patterns. Compare-Lodestar.ps1 now defaults to 50 warmups with -DefaultJit, the count the 1024-unit workloads needed to finish tiering up. The non-Latin-1 index test now builds its vector from all 5,000 symbols instead of 600. New tests cover the cold long-text allocation and unpruned window levels in both queue modes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
PartialRatio is 100 exactly when the shorter string occurs in the longer one, so the string entry point checks that ordinally before building masks or renting buffers: contained or equal 8-128 unit inputs take 6-16 ns instead of 46-1,667 ns, and a 65-unit pattern at the start of a 1,000,065-unit text allocates 3,312 B instead of about 4 MB. Inputs without an exact occurrence pay +1-4% for the scan. Cached WeightedRatio now skips token sort/set when the query and the candidate are both single tokens, as stateless scoring already did (one-token query over 1,000 one-token candidates: 226 -> 160 us, 36 KB -> 4 KB). Cached token-set scoring returns 0 for an empty query before splitting the candidate. New tests compare each shortcut with the full computation. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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
Speeds up the character scoring paths (
Ratio,PartialRatio,TokenSetRatio,WeightedRatioand extraction) and bumps the package to 6.0.4. Scores, alignment tie order, the genericIEquatable<T>API, cached scorers and all 12 target frameworks are unchanged: the 388-pair scoring matrix matches 6.0.3 (ac2e0a2) exactly and Lodestar within1e-9.This branch also carries the benchmark harness commit (
1376f8b) that the measurements below use.Changes
Ratio(direct ASCII index, bounded open addressing otherwise) and a score-onlyPartialRatiopath; the generic implementation stays the authority for alignment coordinates and ties.charLCS kernel on the pattern vector instead of one interface call per symbol: register state for one and two words, stack state above that, absent symbols skipped and a branch-free word carry(u | (s & ~sum)) >> 63.char.IsWhiteSpaceare preserved.[SkipLocalsInit]sits on the short partial-ratio paths and on the Unicode branch of shortRatio, with an internal polyfill for older targets;AllowUnsafeBlocksis required for the attribute, and no unsafe code is added.Results
Measured on an Intel Core Ultra 9 275HX performance core (logical CPU 10), Windows 11, .NET 10.0.15, BenchmarkDotNet 0.15.8, tiering disabled, two launches, no outlier removal. Before = 6.0.3 sources, Lodestar =
52d30ea. Selected rows:Ratio/TokenSetRatio, 256-unit equal-lengthPartialRatio/Ratio, 64-unit ASCIIRatioand the original-phraseWeightedRatio.CharFastPaths-README.mdhas every row, the default-JIT check and the measured decisions.Robustness checks
PartialRatio(8 units, 16-unit equal) is where the cores disagree.Measured decisions
Span.Clear. Depending on what else had run in the process, 1,000-choice extraction took 64.8–74.5 µs; with a single runtime zeroing it was 59.1–60.4 µs in every context. With AVX disabled the related Unicode penalty disappeared (129 → 39 ns), which points to an SSE/AVX transition between the native zeroing helper and nearby 256-bit code.PartialRatiothrough the generic search would remove about 125 lines, but measured +13–36% and 80 B per call. Short queries in longer text are the main use, so the duplicate stays.Test plan
Raffinert.FuzzySharp.6.0.4.nupkgpacks).dotnet test: 5,320 tests each on .NET 8 and .NET 10, 5,313 each on .NET Framework 4.6.2 and 4.7.2.InitLocalson every target.🤖 Generated with Claude Code