Skip to content

Speed up ATX heading and ordered list matching - #233

Open
jvoisin wants to merge 1 commit into
tpope:masterfrom
jvoisin:atx-header-perf
Open

jvoisin wants to merge 1 commit into
tpope:masterfrom
jvoisin:atx-header-perf

Conversation

@jvoisin

@jvoisin jvoisin commented Sep 9, 2026

Copy link
Copy Markdown

The six ATX heading regions (markdownH1..markdownH6) and the ordered list marker start with a bounded whitespace count (" {,3}#" and "%(\t| {0,4})<\d+."), which gives the regexp engine no first character to anchor on. The NFA engine therefore re-scans these at every line start; the backtracking engine rejects non-matching lines quickly.

Force the backtracking engine with %#=1 on these patterns. Highlighting is unchanged. On a mixed 6000-line document this cuts total :syntime engine work roughly in half (each heading region ~-97%, ordered marker ~-44%).

The six ATX heading regions (markdownH1..markdownH6) and the ordered
list marker start with a bounded whitespace count (" \{,3}#" and
"\%(\t\| \{0,4}\)\<\d\+\."), which gives the regexp engine no first
character to anchor on. The NFA engine therefore re-scans these at every
line start; the backtracking engine rejects non-matching lines quickly.

Force the backtracking engine with \%#=1 on these patterns. Highlighting
is unchanged. On a mixed 6000-line document this cuts total :syntime
engine work roughly in half (each heading region ~-97%, ordered marker
~-44%).
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.

1 participant