Repository navigation
Conversation
Three hotspots retried a pattern from every input position, so a long malformed tail cost O(n^2) on the parse thread: - text-fine dedent() dropped the trailing blank run with /\n\s*$/; scanning backward over whitespace keeps the same semantics. - recipe parseAttributes() matched each attribute with /([a-z][a-z0-9-]*)\s*=\s*(["'])(.*?)\2/g; a long run of name characters backtracked at every position. A hand scanner parses name/=/quoted-value directly and keeps the same error codes, duplicate detection and single-line-value rule. - studio parameter source ranges located "name =" with a regex anchored at the prefix end; it still tried every offset. A backward scan finds the same start. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
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.
Closes #453
Summary
Three quadratic-regex findings (~1 s at ~50 KB of adversarial input, all on parse paths reachable from authored files):
dedentinpackages/text-fine/src/surface.tsstripped the trailing blank run with/\n\s*$/. On failure the engine retries the tail from every position —"\n" × Nplus a non-matching tail is O(N²). The run is now removed by scanning backward over whitespace, keeping the exact rule (drop the tail only when it begins with a newline).parseAttributesinpackages/recipe/src/parser.tsmatched each<sheet>attribute with/([a-z][a-z0-9-]*)\s*=\s*(["'])(.*?)\2/g. A long run of name characters with no=backtracks once per position. Replaced with a hand scanner that walks name →=→ quoted value directly. Same error codes (SVS_SHEET_ATTRIBUTE,…_DUPLICATE), same positions on the malformed path, and the old single-line-value rule is kept —.never matched line terminators, so a value containing\n/\r/U+2028/U+2029 still fails as malformed.packages/studio/src/parameters.tslocatedname =at the end of the attribute prefix with a regex anchored by$— still O(prefix × ws-run) because every offset is retried. A backward scan finds the same boundary (<ws>+ name <ws>* = <ws>* quote) in linear time and yields the identical start index; equivalence checked across suffix-name (xstartvsstart), missing-=and boundary cases.Behavior relative to main
dedent<sheet aaaa…>Malformederrorname="Red / green
Existing suites cover semantics: recipe attribute acceptance/duplicates/malformed cases, studio parameter
rangesassertions, text-fine surface decoding — 30 tests pass unchanged. Equivalence of the three replacements was additionally verified by running old-and-new implementations side by side on edge cases before landing.Verification
node --import tsx --test packages/recipe/test/source-closure.test.ts packages/studio/test/parameters.test.ts packages/studio/test/parameter-companions.test.ts packages/studio/test/attribute-groups.test.ts packages/text-fine/test/text-fine.test.ts— 30 pass.pnpm check— clean.Merge Danger
Checklist
Generated with Devin