Avoid revalidating the entire remaining UTF-8 source for every lexer character
Maintainers usually reply within 1 day
A pull request for this has already been merged.
- #965 by @hiyouwhatsapp — merged
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 83/100
Research direction
Start with front/lexer/src/cursor.rs at the advance and peek methods, then read the existing UTF-8 cursor tests added for #392. Check how cursor offsets and diagnostic columns are tracked, and run the lexer tests before and after focused long-input coverage. Done means per-character operations no longer validate the full remaining suffix while UTF-8 handling and spans remain correct; record scaling measurements without a timing assertion.
Written by the indexing model from the issue text.
Description
Problem
Lexer already stores its input as &str, but advance and peek repeatedly call std::str::from_utf8 on the entire remaining suffix. A long comment performs this linear suffix validation for each character, giving quadratic scanning work even though only the next character is needed.
Starting points: front/lexer/src/cursor.rs:25 and front/lexer/src/cursor.rs:47. Preserve the UTF-8 byte-offset and diagnostic-column contract; this is a cursor hot-path fix, not a lexer redesign. #392 added UTF-8 correctness tests but does not cover repeated suffix validation.
Reproduction
Audited canonical master d59bdab376bdc04edacdc8029b256cb8d55b5adf on Linux amd64 with a checkout-built Wave 0.0.1-alpha-dev, Rust 1.89.0 and LLVM 21.1.8.
With the debug compiler, checked files containing /* + N ASCII a characters + */\nfun main() {}\n, three executions per size:
| Comment bytes | Elapsed seconds |
|---|---|
| 30,000 | 0.0707, 0.0633, 0.0665 |
| 60,000 | 0.2024, 0.2087, 0.1956 |
| 120,000 | 0.7333, 0.7140, 0.7221 |
All checks succeed. Doubling the long comment approaches four times the scanning cost. These are debug-build observations, not release benchmark claims. The repeated full-suffix validation is also directly visible in the source.
Reproduce with target/debug/wavec check long-comment.wave; use time.perf_counter() around repeated subprocess invocations and keep the number of tokens constant.
Scope
Decode/look ahead within the already-valid string without scanning its full suffix again. Difficulty: easy; the existing UTF-8 cursor tests provide a starting point.
Completion criteria
- Preserve multibyte identifiers, comments, strings, CR/LF tracking and diagnostic spans.
- Remove full-suffix UTF-8 validation from per-character cursor operations.
- Add focused long-input correctness coverage and record scaling measurements; avoid a flaky wall-clock assertion in unit tests.
- Dominant language
- Rust
- Stars
- 56
- Forks
- 21
- Avg merge
- 4h 41m
- Merged PRs (30d)
- 58
Getting set up
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 wavefnd/Wave
-
bug good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
enhancement good first issue needs testing
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
bug good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Distinguish Rust character literals from lifetimes in the spacing helperPossibly taken A pull request linked to this issue is open or already merged. Openbug good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
documentation enhancement good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
Similar issues
-
area: supply-chain
Difficulty 1/5 Under an hour Newbie friendliness 73/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
-
Refresh stale docsOpen
Difficulty 1/5 1-3 hours Newbie friendliness 67/100
OpenCarControls/firmware#35 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day