Skip to content

Move hot-path consumers back to direct scans.#2507

Merged
jhy merged 2 commits into
masterfrom
perf/characterreader
May 14, 2026
Merged

Move hot-path consumers back to direct scans.#2507
jhy merged 2 commits into
masterfrom
perf/characterreader

Conversation

@jhy

@jhy jhy commented May 14, 2026

Copy link
Copy Markdown
Owner

Make the parser-hot CharacterReader scanners use direct delimiter loops instead of routing through consumeMatching(CharPredicate).

The lambda predicates looked cleaner, but would not always get a good JIT and could stay in virtual dispatch. That led to a wide variance in throughput.

This keeps the generic predicate scanner for lower-traffic cases, but gives the main HTML tokeniser scanners monomorphic loops that the JIT can compile more predictably.

Fixture Baseline avg ops/s Baseline min Baseline max Baseline spread New avg ops/s New min New max New spread
tiny 447,238 375,236 497,448 27.3% 471,773 460,019 478,158 3.8%
small 58,630 58,031 59,325 2.2% 85,310 81,470 86,786 6.2%
medium 20,764 19,626 27,966 40.2% 27,648 27,524 27,836 1.1%
large 597 592 607 2.5% 598 591 606 2.5%
x-large 184 182 186 2.4% 182 175 184 5.2%

The spread really seemed to be dependent on the contents of the fixture more than the size.

The lambda predicates looked cleaner, but would not always get a good JIT and could stay in virtual dispatch. That led to a wide variance in throughput.
@jhy jhy added the improvement An improvement / new feature idea label May 14, 2026
@jhy
jhy merged commit 6145bd5 into master May 14, 2026
22 checks passed
@jhy
jhy deleted the perf/characterreader branch May 14, 2026 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement An improvement / new feature idea

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant