feat(hyphenate): add trie based hyphenation package - #3494
Merged
Conversation
Adds @react-pdf/hyphenate, a Liang hyphenation engine with an entry point per language. Patterns are compiled into a trie once instead of being scanned one by one, and results are cached per language. Pattern data is read from hyphen rather than vendored, so the language sets stay maintained upstream.
🦋 Changeset detectedLatest commit: 01bc3a8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Adds
@react-pdf/hyphenate, a Liang hyphenation engine with an entry point per language.Patterns are compiled into a trie once and matched with a walk from each offset, instead of scanning every pattern in the set per word. Results are cached per language.
Pattern data is read from
hyphenrather than vendored, so the language sets stay maintained upstream. The dependency is pinned to the1.6line because later releases ship pre-compiled tries in a different shape.Usage
86 languages are generated at build time from the pattern sets, each its own entry point so bundlers only include what is imported.
Comparison
20,000 unique English words, each library in its own process, best of five. Sizes are an
en-usbundle, minified and gzipped.en-uspatterns@react-pdf/hyphenatehypher0.2.5hyphenated1.2.0@lunarisapp/hyphen1.2.1hyphen1.6.4Notes
hyphenacross 258,231 tokens: 0.115% differ, all words where the same pattern occurs twice close together (possessesbecomespos-sess-esrather thanpos-sesses).hyphenskips those matches; this does not.hyphen1.6's own behaviour — it seeds them under keys it never looks up.