xoofx / markdig

A fast, powerful, CommonMark compliant, extensible Markdown processor for .NET
BSD 2-Clause "Simplified" License
4.41k stars 456 forks source link

Rendering large text. #825

Open p6laris opened 6 days ago

p6laris commented 6 days ago

Hi there,

I’m working on a project where I need to render large Markdown documents into HTML using Markdig. The issue I’m running into is performance when re-rendering the entire document after every change. I’d like to optimize this process by only re-rendering the sections that have been modified or added.

I’m wondering if there’s a way to achieve this using or any suggestions?

Cheers.

xoofx commented 1 day ago

I’m wondering if there’s a way to achieve this using or any suggestions?

It would require maintaining the previous document model in memory and performing your own diff, and removing the nodes that are the same and then re-render things... but yeah, it will be complicated. You will need to identify where previous blocks map to previous text in order to do a safe replacement. It's possible (e.g. you can hook into the HTML renderer to record the line + associated markdown block)

How large is your input document and how frequent do you have to re-render it?