Skip to content

Match escapable characters after a backslash without a regex - #480

Merged
robinst merged 1 commit into
commonmark:mainfrom
g4lb:perf-backslash-escapable
Nov 28, 2026
Merged

robinst merged 1 commit into
commonmark:mainfrom
g4lb:perf-backslash-escapable

Conversation

@g4lb

@g4lb g4lb commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

BackslashInlineParser uses a regex for the character after a backslash. This change uses an AsciiMatcher with the same 32 characters.

JMH, JDK 21, Apple M-series:

Input main this branch Change
Text with many escapes, parse 387 µs 296 µs −23.6%
Same text, parse and render 410 µs 326 µs −20.5%

No input of the 30 is slower. The output is the same on 2.1M inputs. Tests pass on JDK 17 and 21.

@robinst
robinst merged commit dc9c42e into commonmark:main Nov 28, 2026
5 checks passed
@robinst

robinst commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

Nice, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants