You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Suggestion]: reactivity in node-level diffing for createParse() #135
when rendering Comark in a framework (Vue, React, Svelte), every call to parse() produces an entirely new AST. framework renderers see all-new object references and re-render the entire document tree, even if only a single character changed in one paragraph
This is costly for:
Streaming/AI chat: tokens arrive rapidly but only the last node is actively changing
Live editors: users edit one section while the rest is static
Expensive plugins: syntax highlighting and math rendering run on every node, every time
Proposal
add automatic node-level diffing to createParse() when the returned parser is called multiple times, it compares the new AST against the previous result and preserves === object references for structurally unchanged nodes
framework renderers can then skip re-rendering nodes whose reference didn't change with zero API changes for consumers. here's a video of react example with react-scan (look at the AST section)
There is such feature in the streaming mode. When you pass { streaming: true } to the parse function, parser will keep the latest result and try to optimize parsing.
This will happen only if the first input is a prefix of next input. on this situation, parser will try to extract previously parsed complete block and reuse their node and prevent from parsing again.
As result, streaming is faster and more memory efficient.
Activity
farnabaz commentedon Apr 17, 2026
There is such feature in the streaming mode. When you pass
{ streaming: true }to theparsefunction, parser will keep the latest result and try to optimize parsing.This will happen only if the first input is a prefix of next input. on this situation, parser will try to extract previously parsed complete block and reuse their node and prevent from parsing again.
As result, streaming is faster and more memory efficient.
Try this.
atinux commentedon Apr 17, 2026
I think it could be nice to document this for some kind of parsing with hoisting? (not sure if this is the right name :D )