frontend: _SPACE_BEFORE_BLOCK takes quadratic time on a long run of whitespace
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 80/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- python
- Domain
- performance
Research direction
Start at scriptconv/frontend.py line 114, where _SPACE_BEFORE_BLOCK = \s\W*$ is defined, and line 1140, where the block join searches it across the whole preceding text. Run the repro snippet to confirm the quadratic growth, then pin down what the pattern must still match (trailing whitespace plus non-word characters) so the replacement keeps that meaning — e.g. strip the tail and test the last character, or search an end-anchored pattern on the reversed tail. Done means the 20,000-space case is fast and the existing frontend tests pass.
Written by the indexing model from the issue text.
Description
🤖 Auto-generated by Claude Opus 5.5 (claude-opus-5-5) via Claude Code — NOT human-reviewed. Verify before acting.
Verified against source: the lines and outputs below were read and run on scriptconv origin/dev 03b4c08.
Observed
_SPACE_BEFORE_BLOCK in scriptconv/frontend.py (line 114) is \s\W*$, and the block join searches it over the whole text before a block (line 1140). On a long run of whitespace that a letter follows, the search time grows with the square of the run length:
| Text searched | Time |
|---|---|
a, 5,000 spaces, b |
1.40 s |
a, 10,000 spaces, b |
3.04 s |
a, 20,000 spaces, b |
7.92 s |
The timings come from a loaded machine, so the absolute values are high. The growth from 10,000 to 20,000 is the point.
Expected
The check reads only the end of the text, so its time does not depend on the length of the whitespace before the end. For example, strip the end of the text and test the last character, or search a pattern anchored at the end on the reversed tail.
Reproduce
import time
from scriptconv.frontend import _SPACE_BEFORE_BLOCK
text = "a" + " " * 20000 + "b"
start = time.perf_counter()
_SPACE_BEFORE_BLOCK.search(text)
print(time.perf_counter() - start)
Where
scriptconv/frontend.py line 114 (the pattern) and line 1140 (the search in the block join). The review of #353 found the case.
- Dominant language
- Python
- Stars
- 4
- Forks
- 1
- Avg merge
- 8h 57m
- Merged PRs (30d)
- 118
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from TigreGotico/scriptconv
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
TigreGotico/scriptconv#412 ·
Maintainers usually reply within 1 day
-
docs: the ByT5 docstring says it downloads, and the _stress docstring says stressonnx is not on PyPIOpen
Difficulty 1/5 Under an hour Newbie friendliness 88/100
TigreGotico/scriptconv#411 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
TigreGotico/scriptconv#410 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
TigreGotico/scriptconv#409 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
TigreGotico/scriptconv#394 ·
Maintainers usually reply within 1 day
All issues in TigreGotico/scriptconv
Similar issues
-
area: ci enhancement perceived difficulty: 1
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Nitjsefnie-Harness-Commons/daedalus#1826 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
vllm-project/vllm-sail#398 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
DiamondLightSource/sm-bluesky#476 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
jenkinsci/user-guide-ai-chatbot-plugin#132 ·
Maintainers usually reply within 6 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100