Skip to content

👌 Fix quadratic-time smartquotes on blocks with many quotes - #481

Open
affan-arch wants to merge 1 commit into
executablebooks:masterfrom
affan-arch:smartquotes-linear-time
Open

affan-arch wants to merge 1 commit into
executablebooks:masterfrom
affan-arch:smartquotes-linear-time

Conversation

@affan-arch

Copy link
Copy Markdown

make smartquotes linear in the number of quotes by porting markdown-it's deferred replacements (9ce2087, which upstream lists under Security) and dropping the per-quote text[pos:] copy, the per-token stack copy and the full-stack rescan for a closer with no opener of its kind; with typographer on, a 117 KiB block (' "a' * 20_000 + " b'" * 20_000) used to stall a render for ~10 s and now takes 0.03 s, upstream's '"' * 160_000 case goes from ~4 s to 0.11 s, and the output matches the old rule on 390k fuzzed inputs.

Port markdown-it's deferred replacements (9ce2087) and remove the other
O(n) work done per quote or per token in process_inlines: the
text[pos:] search, the stack copy per token, and the full-stack rescan
for a closer with no opener of its kind.

This branch has not been deployed

No deployments
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