Skip to content

Reuse the single choice cache in serial cdist - #519

Open
wozhenbang2004 wants to merge 2 commits into
rapidfuzz:mainfrom
wozhenbang2004:perf-cdist-short-choice-cache
Open

wozhenbang2004 wants to merge 2 commits into
rapidfuzz:mainfrom
wozhenbang2004:perf-cdist-short-choice-cache

Conversation

@wozhenbang2004

Copy link
Copy Markdown

Refs #136.

The non-SIMD cdist path creates a cached scorer for every query, even when there is only one choice. For symmetric scorers with serial workers (0 or 1), initialize the cache from that choice on the first valid comparison and reuse it across queries. Keep the existing argument order for asymmetric scorers, and leave the parallel and SIMD paths unchanged.

Add 39 compatibility cases that compare native and Python results for cutoffs, hints, processors, output types, missing values, asymmetric weights, and worker settings.

Validation on Python 3.12.14 with the native Release build (-O3, project-default LTO):

  • A forwarding probe of the real WRatio C API records 5 cache initializations on the base and 1 with this change, with identical scores. Asymmetric, multiple-choice, parallel, and SIMD controls keep their existing cache counts.
  • In a local, seeded 10,000-by-1 workload, balanced A/B/B/A runs give median WRatio times of 11.68 ms before and 6.34 ms after, and token-set times of 5.80 ms before and 4.38 ms after. These are workload-specific measurements; all benchmark matrix hashes match.
  • 2,202 cutoff-boundary comparisons match exactly. Of 243 broader public-API comparisons, 240 match exactly; the other three exercise an unchanged SIMD missing-value path whose leading None returns unstable values in repeated runs of both versions.
  • Full suite: 581 passed, with the existing test_score_cutoff_equal_to_score[scorer9] failure. The unmodified base has the same failure with 542 passed.
  • pre-commit run --all-files and git diff --check pass.

This branch has not been deployed

No deployments
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