Skip to content

Optimize PartialRatio edge scans, multiword LCS and TokenSetRatio - #39

Merged
ycherkes merged 13 commits into
masterfrom
perf/incremental-lcs-token-set
Nov 28, 2026
Merged

ycherkes merged 13 commits into
masterfrom
perf/incremental-lcs-token-set

Conversation

@ycherkes

@ycherkes ycherkes commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Changes

  • Scan PartialRatio prefixes and suffixes with incremental bit-parallel LCS rows, preserving the existing interior branch-and-bound search, score arithmetic and alignment tie ordering.
  • Reuse the owned single-word pattern vector for reversed suffix scans. Patterns of 9–64 elements avoid a second vector; tiny patterns retain direct edge comparisons. Multiword suffix masks are populated without a reversed input-array copy.
  • Share a borrow-free multiword LCS update between similarity, matrix construction and edge scans. Multiword edge scans now retrieve symbol presence and its mask with one internal TryGetMask call instead of separate ContainsKey/GetOrZero calls.
  • Compute built-in TokenSetRatio prefix comparisons from lengths and return early for nonempty token subsets. Custom and partial scorers retain their original scoring calls and empty-input behavior.
  • Record the changes under v6.0.3 in the changelog, use package-facing README wording, and preserve links to the original FuzzySharp, Fastenshtein and Quickenshtein.
  • Add reproducible multiword PartialRatio benchmarks for 65/257/1025-element ASCII and Cyrillic strings. Refresh both README benchmark tables from one complete Classic comparison run.
  • Keep generated benchmark reports out of the PR. Sources, reproduction commands and measured summaries remain in the repository.

Correctness and validation

  • Added 30 long-window regression cases: exhaustive independent DP checks across unequal lengths and 63/64/65, 127/128/129, 257 and 1023/1024/1025/2049 boundaries; exact and near-exact interior windows; first/last windows; edge alignments that beat interior windows; ties; and swapped coordinates. Generic integer and string/Unicode paths are checked.
  • Added allocation regression tests on .NET 8/10 and in-place mask checks for ASCII, non-ASCII and generic vectors. The single-word allocation check uses an upper bound of two vectors and the minimum of eight batches to tolerate transient pool refills. It passed 100 extra cases under concurrent Gen2 GC and rejected all five cases on the pre-reuse implementation.
  • Added nine cases covering 131,072 byte carry combinations, 4,000 randomized multiword rows against an independent bitwise full-adder, and internal mask lookup for present/absent symbols, including a symbol present only in the final mask word.
  • Release solution build passed for all 12 library target frameworks, including net45.
  • Full suites passed: 5,256 tests each on .NET 8 and .NET 10; 5,251 tests each on .NET Framework 4.6.2 and 4.7.2. Total: 21,014 executions, zero failures or skipped tests.
  • The existing Microsoft.Bcl.Memory support warning for netcoreapp3.1 remains.

Performance verification

The measured library source is e60e993, before the subsequent token-set scorer refactor in e01550c. These numbers describe that measured snapshot; the later refactor was integrated and tested but not rebenchmarked.

Reran all 71 published workloads, plus three calibration controls, using BenchmarkDotNet 0.15.8, Release, .NET 10.0.15 / SDK 11.0.100, Windows 11, Intel Core Ultra 9 275HX. Sequential methods run on P-core 10; parallel extraction uses P-cores 10–13. Core classes were checked through Windows CPU Set Information. Two launches, six warmups and ten measured iterations per launch, 300 ms target, no outlier removal. Tiered compilation and dynamic PGO are disabled. This is a controlled JIT configuration, not the runtime default.

All 71 results had 99.9% confidence-interval half-widths below 5% of the mean. Tables in both READMEs now include the intervals and reproduction commands. These replace the noisy unrestricted-affinity measurements; absolute times across different JIT/affinity configurations are not a code-regression comparison.

Control Calibration Full series Drift
Ratio 55.82 ± 0.75 ns 55.47 ± 0.54 ns -0.63%
Classic Ratio 174.32 ± 2.06 ns 174.65 ± 1.79 ns +0.19%
Fastenshtein batch 97.150 ± 0.342 ms 97.087 ± 0.439 ms -0.06%
Operation Measured build Classic 2.0.2 Speedup
Ratio 55.47 ± 0.54 ns 174.65 ± 1.79 ns 3.15×
PartialRatio 246.00 ± 2.14 ns 613.00 ± 8.36 ns 2.49×
TokenSetRatio 325.20 ± 3.70 ns 2,017.90 ± 6.99 ns 6.21×
WeightedRatio 3,125.00 ± 47.00 ns 8,984.00 ± 25.30 ns 2.87×
PartialRatio, 17-character pattern in 517-character text 1,051.00 ± 6.40 ns 10,976.00 ± 48.70 ns 10.44×
ExtractOne 5.449 ± 0.019 μs 19.320 ± 0.253 μs 3.55×
ExtractAll 5.633 ± 0.016 μs 19.372 ± 0.176 μs 3.44×

Intervals are BenchmarkDotNet's 99.9% confidence-interval half-widths. The benchmark README includes cache/parallel variants, allocations, distance workloads, all six multiword comparisons and calibration controls. Partial-ratio algorithms and rounding differ between libraries, so equal scores are not asserted; Classic comparisons do not isolate the mask-lookup change alone. Generated reports remain ignored.

Bump the package version to 6.0.3, with assembly/file version 6.0.3.0. NuGet and symbol packages build successfully for all 12 targets. No public API changes.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-28T12:33:13.363769Z 070dbeb Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ycherkes
ycherkes force-pushed the perf/incremental-lcs-token-set branch from 6aa03c3 to fcf7855 Compare November 28, 2026 08:29
ycherkes and others added 5 commits November 28, 2026 10:05
Replace CanReturnPerfectScore and ScorePrefix with one internal
UsesBuiltInIndelRatio flag, and move the shared shortcut, prefix-length
scoring and final comparison into TokenSetScorerHelpers.Score so the
cached and uncached scorers use one implementation. Behavior is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0136UBH4NoG4664Uiz2aF6Yh
@ycherkes

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 070dbeb9f9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ycherkes
ycherkes merged commit ac2e0a2 into master Nov 28, 2026
2 checks passed
@ycherkes
ycherkes deleted the perf/incremental-lcs-token-set branch November 28, 2026 12:34
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.

2 participants