Skip to content

refactor: optimize regex compilation and fix distance logic#124

Open
minibikini wants to merge 3 commits into
masterfrom
fix/optimize-and-refactor-logic
Open

refactor: optimize regex compilation and fix distance logic#124
minibikini wants to merge 3 commits into
masterfrom
fix/optimize-and-refactor-logic

Conversation

@minibikini
Copy link
Copy Markdown
Owner

@minibikini minibikini commented Dec 18, 2025

This PR introduces two main improvements:

  1. Performance Optimization: Script detection regexes are now compiled at build time instead of runtime, significantly reducing overhead for every call to `detect`.
  2. Logic Fix: The distance calculation algorithm has been corrected to compare trigram ranks instead of trigram counts. This aligns the logic with the original Franc algorithm and improves stability for texts of varying lengths.

Tests have been updated to reflect the slightly adjusted probability scores resulting from the logic fix.

Benchmark Results (Short Text)

Metric Master Fix Improvement
Time ~296 µs ~245 µs ~17% faster

Benchmark Results (Long Text)

Metric Master Fix Improvement
Time ~868 µs ~803 µs ~7.5% faster

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