Repository navigation
Conversation
Skip normalization when it cannot change parser state and build the left substring once. Keep the normalization window and shared state machine. Co-Authored-By: Aiden <aiden@weco.ai>
Owner
|
I am not going to have time to review a performance improvement any time soon. |
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.
TL;DR
split_string_at_unquoted_specialwhen parsing long email input.pytest tests/test_syntax.py tests/test_main.py tests/test_deliverability.pypasses all 344 tests.What & Why
The splitter normalizes a short window at every character and builds the left substring one character at a time.
Most characters cannot change quote, escape, or delimiter state.
Check normalization only where it can affect those states, then use a slice for ordinary strings.
Keep the existing 32-character window and string-subclass operations so parsing results stay the same.
Validation
Measurements use CPython 3.12 on Linux, with DNS checks disabled for syntax validation.
The regression and ordinary-address rows use pytest call durations, rounded to milliseconds.
Values below 1 ms show no measurable change at that resolution; they do not prove identical latency.
@example.comThe repeated workload includes the long input plus short Unicode, quote, escape, display-name, and invalid-address cases.
These statistics summarize three runs of that workload:
To reproduce the repository regression timings:
python -m pytest tests/test_syntax.py -k 'long_input or long_idna' \ --junitxml=timings.xml -o junit_duration_report=callThe project flake8 and mypy checks also pass.
Why this is safe and easy to maintain
The change keeps one shared state machine and adds three net code lines.
Quote, escape, delimiter, and error behavior stay unchanged.
Existing syntax tests cover Unicode composition, quoted local parts, display names, and long input.
AI assistance
This PR was prepared with AI assistance from Aiden. Candidates were tracked with Weco Observe.
Weco share link: https://dashboard.weco.ai/share/M8ZZgv-1eOo8hzemcc-T9rSBxZiICnvg