Read diagnostic codes off their text in linear time - #169
Closed
luisleo526 wants to merge 1 commit into
Closed
luisleo526 wants to merge 1 commit into
luisleo526 wants to merge 1 commit into
Conversation
The classifier fullmatched each catalog template as a regex with lazy (.*?) arguments over the message and hint. Text a script spells reaches those arguments, and with several arguments the regex backtracked over every split: 0.55 s for 1.8 KB and 23 s for 3.4 KB of one template's text. Each literal now goes to its leftmost place after the previous one, the last to the text's end. That is the split the lazy regex returns, and the only one tried when no argument name repeats, since a leftmost place leaves the rest the most room. Where a name repeats (a receiver in the message and the hint), later places are tried in the regex's order within a budget of 4,096 places. The same crafted text, grown to 6.6 MB, now classifies in milliseconds. Codes and args are unchanged: - 669 distinct real texts (corpus, fixtures, suite); - 7,512 generated samples, plain and holding the templates' own literals; - tests/test_diagnostic_codes.py now pins equality with a reference lazy-regex matcher, and a timing bound on flooded text. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Contributor
Author
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.
Summary
A follow-up to #166: diagnostic codes are now read off their text in linear time.
diagnostic_codes.classifyfullmatched each catalog template as a regex with lazy(?P<x>.*?)arguments, compiled with DOTALL over the message, a NUL and the hint. Text a user's script spells (identifiers, expressions, request keys) reaches those arguments. With several arguments the regex backtracked over every split.code, so the Pyodide worker reads it for every diagnostic.{receiver}in the message and the hint (obj.field[1]holds the separator.). For those, later places are tried in the regex's order within a budget of 4,096 places. A crafted text that exhausts the budget getsPF-E0000/PF-W0000.Evidence
tests/test_diagnostic_codes.py::test_classification_is_the_lazy_regex_splitpins this against a reference lazy-regex matcher.test_classification_is_linear_on_crafted_textbounds the time on flooded text.285ac03, one fresh process per file over 325 corpus and 263 fixture sources:codeandargs: 1218/1218 identical.f3bf9f07adfaand codegen3ba9edf5f968, against the active baselinepineforge-parity-baseline-20261004-codegen-285ac035, recorded.verdict-f3bf9f07adfa-3ba9edf5f968-04e60e8ca489, receipt3f23bc32….rj-20261004t134808-4d1a31, enginef3bf9f07):test_array_history.py::test_many_bindings_are_walked_once_each, a 40 s wall-clock budget under full-suite xdist contention.rj-20261004t133235-e4c237), ran it at 13.4–14.3 s on463a9afand 13.6–13.8 s on521a6e9b.Test plan
tests/test_diagnostic_codes.py: 600 tests pass locally, including the two new ones.🤖 Generated with Claude Code