Skip to content

perf(reflow): merge emphasis and code span extraction into a single cmark pass#732

Open
chandlerc wants to merge 3 commits into
rvben:mainfrom
chandlerc:perfreflow-merge-emphasis-and-code-span-/zwywxqstwnxk
Open

perf(reflow): merge emphasis and code span extraction into a single cmark pass#732
chandlerc wants to merge 3 commits into
rvben:mainfrom
chandlerc:perfreflow-merge-emphasis-and-code-span-/zwywxqstwnxk

Conversation

@chandlerc

Copy link
Copy Markdown
Contributor

Update parse_markdown_elements_inner to extract both emphasis spans and
code spans in a single shared pulldown-cmark parser run.

This reduces the number of separate markdown parsing passes per paragraph from
three to two, avoiding redundant tokenization overhead. The link extraction pass
must remain separate due to broken-link resolution shifting delimiter pairings in
corner cases. A standalone extract_code_spans is retained only for the mask
calculation utility.

Note that this is based on #731 and #730 -- only the last commit is for review here.

Assisted-by: Antigravity with Gemini

…ode spans

Update myst_role_len_at to verify its trailing inline code span using
a fast binary search check on the pre-extracted code spans list instead of
manually searching for backtick delimiters.

Assisted-by: Antigravity with Gemini
…xt elements

Update fallback paths inside parse_markdown_elements_inner to slice using
char::len_utf8() instead of hardcoded 1-byte indices. This prevents thread
panics when the parser falls back on multi-byte (CJK or emoji) character
boundaries.

Also merge contiguous Element::Text elements together before returning
from the parser to clean up the output slice.

Assisted-by: Antigravity with Gemini
…mark pass

Update parse_markdown_elements_inner to extract both emphasis spans and
code spans in a single shared pulldown-cmark parser run.

This reduces the number of separate markdown parsing passes per paragraph from
three to two, avoiding redundant tokenization overhead. The link extraction pass
must remain separate due to broken-link resolution shifting delimiter pairings in
corner cases. A standalone extract_code_spans is retained only for the mask
calculation utility.

Assisted-by: Antigravity with Gemini
@chandlerc

Copy link
Copy Markdown
Contributor Author

BTW, let me know if you'd rather I handle a stack of changes in some other way -- using the last commit has worked for me in some other projects, but happy to adopt whatever workflow works for you.

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