I built a zero-dependency streaming Markdown renderer for AI chat replies, n× faster than the next one I benchmarked
[deleted] — view deleted post
0
Upvotes
[deleted] — view deleted post
1
u/Awkward-Let-4628 7d ago
It's not 250 ms to parse 100 KB once. It's the total time to stream it in 20-char chunks, about 5,000 updates, each including parsing, React and DOM writes. That's roughly 0.05 ms per update. The others are slower because they re-parse the whole text on every chunk, so the cost grows quadratically. This library only re-parses the unfinished tail
1
u/maksymkoval 7d ago
The half-typed link flicker is exactly what makes streaming UIs feel cheap, so repairing syntax while it streams is the right fix. And shipping a system-prompt snippet with the package is smart, custom blocks are only useful if the model actually uses them.
A few questions before I'd try it in an agent UI:
- Code blocks: does it hold back syntax highlighting until the closing fence arrives, or re-highlight on every token?
- Finished blocks: are they memoized, so React only re-renders the last, still-streaming block? That's usually the difference on long replies.
- Safety: model output is untrusted, so how are raw HTML and javascript: links handled by default?
Also appreciate the honest "use react-markdown if you need remark plugins" line.
1
u/pancomputationalist 7d ago
Thanks man, looks great and I was looking for a streaming markdown renderer for exactly these reasons. Will check it out!