perf(tokenizer): scan quoted attribute values in one loop
G4
9d ago+14+14+01234567890123456789-2-2-0123456789
With decodeEntities: false, the tokenizer skips to the closing quote of an attribute value. With the default decodeEntities: true, each character of the value goes through the parse loop. Now this path also skips, to the next quote or &. The output does not change.
parseDocument on the built dist:
| Input | Before (Node 22) | After (Node 22) | Node 22 | Node 20 |
|---|---|---|---|---|
| Wikipedia "HTML" page, 809 KB | 6.20 ms | 4.89 ms | -21.2% | -12.0% |
| GitHub repository page, 333 KB | 1.92 ms | 1.56 ms | -19.0% | -12.3% |
MDN <table> page, 248 KB | 1.58 ms | 1.42 ms | -10.2% | -5.3% |
<a href="…"> with a 50,000-character value | 194 µs | 35.7 µs | -81.5% | -75.9% |
I used 16 interleaved rounds and a Mann-Whitney test (Apple M5, Node 22.23.1 and 20.20.2). I did not measure other engines.
Slowdowns, in 57 benchmarks:
- Attribute values with an entity after each character: +4.0% on Node 22, +1.1% on Node 20. Values with only entities: +3.1% on Node 22, -0.2% on Node 20.
- The Markdown syntax page, 32 KB: +1.9% on Node 20. It is 1.6% faster on Node 22.
- All other benchmarks that are not faster show no significant change. The old code against itself shows no significant change in any benchmark.
This PR does not change fastForwardTo, so it does not overlap with #2525.
Checks:
npm testpasses on Node 22, andvitestpasses on Node 20.- Old and new outputs matched on 3,040,000 results: events, positions, DOM, and tokenizer callbacks, with chunked input.
Summary by CodeRabbit
- Bug Fixes
- Quoted attribute values are now parsed through to the next quote, character reference, or end of available input, improving handling of values split across input buffers.