Skip to content

Scan comments and strings with memchr - #3

Merged
TomasVotruba merged 1 commit into
mainfrom
lexer-memchr
Dec 3, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
lexer-memchr

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

After the arena change the lexer is the biggest part of the profile (~42% of CPU). This scans the bulk content with SIMD search instead of byte by byte:

  • single quoted strings - memchr2 for the quote and the backslash
  • block comments - memmem for */
  • line comments - memchr3 for the line break and ?
  • line breaks inside them are recorded in one pass over the consumed range

About 5% fewer instructions on the Laravel corpus (9.04 -> 8.58 billion, single thread). The dump stays byte-identical to the Go parser on Laravel (8.4, 7.4), Symfony (8.4, 7.4) and a PHP 7.4-era Laravel (7.4, 5.6).

Adds the memchr crate.

@TomasVotruba
TomasVotruba merged commit 6869bda into main Dec 3, 2026
3 checks passed
@TomasVotruba
TomasVotruba deleted the lexer-memchr branch December 3, 2026 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant