Repository navigation
Conversation
Two patterns tried every split of the rest of the name from every start
that could not match, which is cubic in the length:
- altTitlesRegex on a name with Cyrillic or CJK letters and no "/" or "|":
1000 letters took 1.4 s, 3000 about 30 s;
- russianCastRegex on brackets that do not close the name: "а(" repeated
to 1024 characters took 0.3 s, to 3000 about 9 s.
A lookahead for the place each alternative has to end at anyway fails
those starts at once and changes no match.
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
This branch has not been deployed
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.
Two patterns in
cleanTitlebacktrack through every split of the rest ofthe name from every start that cannot match, so the time grows with the cube
of the length. A long name without the character the pattern has to end at
takes seconds:
'Фильм ' + 'а'.repeat(1000)'Фильм ' + 'а'.repeat(3000)'а('.repeat(512)'а('.repeat(1500)'a/('.repeat(1000)altTitlesRegex: a name with Cyrillic or CJK letters and no/or|.The first alternative is
[^/|(]*[…][^/|]*[/|]; with no separator aheadeach start tries every position of the letter and every length of the tail.
russianCastRegex: brackets that do not close the name. Both alternativesend with
\)$.Fix: a lookahead in each alternative for the place it has to end at anyway —
(?=[^/|]*[/|]),(?=[^)]*\)$),(?=.*\)$). A start that cannot end therefails at once. No match changes: every match of the old alternative satisfies
the lookahead, and the alternatives are tried in the same order.
Checked: the old and the new pattern give the same matches (index and groups)
on the titles of the test corpus and on 800k random strings over the
characters the patterns tell apart;
parseTorrentTitlereturns the same JSONfor all 1,156 titles of
bench/corpus.cjsand 3,976 tracker titles.Tests: src/tests/longTitle.test.ts, 1349 tests pass. The remaining
patterns in
cleanTitleare quadratic at worst (about 10 ms for a name of1024 characters).
🤖 Generated with Claude Code