MeanderingProgrammer / render-markdown.nvim

Plugin to improve viewing Markdown files in Neovim
MIT License
1.38k stars 33 forks source link

Replace text change events with nvim_buf_attach #84

Closed MeanderingProgrammer closed 1 month ago

MeanderingProgrammer commented 1 month ago

Using events to re-render the entire file is not very efficient. Instead we can use callbacks provided by nvim_buf_attach to figure out which text changed and create / remove only the necessary marks.

MeanderingProgrammer commented 1 month ago

There are a couple limitations that make this tricky but I think I can work through them. Lately I've focussed on optimizing the code as it runs now and have gotten some pretty awesome performance improvements on larger files. Mostly to do with how we pull conceal information and handling tables a little better by avoiding redundant processing:

MeanderingProgrammer commented 1 month ago

I believe this last change (https://github.com/MeanderingProgrammer/markdown.nvim/commit/c7a20552b83c2abad92ac5e52feb7fe3b929f0a7) to only parse visible content ranges fulfills the heart of this issue, though going about it in a different way.

Nearly any file size now works with little noticeable impact waiting for this plugin to do its thing. At this point doing a minimal diff kind of parsing, while still better, is probably not necessary.