-
-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: parallel rendering of latex snippets #1372
base: main
Are you sure you want to change the base?
Conversation
@jonboh could you upload the large latex file? I've been working on improving this module as well and I'd like to test with a large file b/c currently my implementation doesn't hang neovim at all. |
sure, here's the file I've been using for testing:
|
@benlubas have you uploaded your changes to your fork? I'll be happy to give them a try If you don't mind, there are still some things in this pr that don't work great, wheneve the images are moved by a line there's a slight delay, which is noticeable if you keep pressing Down, but I think that is related to |
I'm in the middle of rewriting mine to fix the move up/down flickering issue. I can go grab a revision that's working and link it here for you to try though! It takes advantage of a change that was just merged into image.nvim yesterday, so make sure you update image.nvim. https://github.com/benlubas/neorg/tree/feat/async_images Here, this should work actually I haven't pushed anything breaking. I will warn you that with a large number of images it starts to get really really slow, it's definitely still a WIP. The things that are working: inline images with conceal. conceal/unconceal on cursor move. updates the images when you change text. Images are displayed accurately even if there are virtual lines above the image. |
I'm trying the |
My branch is going to change a lot in a few days, I might work on it a bunch more today now though |
I think we shouldn't write a base64 module here |
I wasn't aware of |
I've added as well a fix to handle cases in which the math snippet does not compile to an image, for example Now a small log message will be generated indicating which snippet could no be compiled. |
@jonboh Just opened a PR for image.nvim that can fix a lot of the performance issues I was having. It should also fix your performance issues. 3rd/image.nvim#141 try it out, and let me know how it goes. (it might break something, but I couldn't think of anything that would break) |
Hi! I've been using the latex renderer for some of my notes and I noticed its performance scaled badly with the amount of equations in the document. In short, equations currently are rendered one by one, in a blocking manner.
This PR performs all the renderings in parallel.
Here is an example of the difference:
Current
main
behavior (around 13s until the user gets back control):https://github.com/nvim-neorg/neorg/assets/31407988/f004090c-92bb-4f67-8187-d31997b05b27
This pr (3 to 4s until the user gets back control):
https://github.com/nvim-neorg/neorg/assets/31407988/1104073e-700b-44c1-a5b1-e41abf2592c3
I've made a bunch of changes to the latex renderer that I think improve its usability:
latex_renderer
so that all latex_snippets are extracted and rendered in parallel jobs. This way we only need to wait for the longest render.render_latex
do not need to perform the conversion fromlatex
topng
.I've added the same base64 utility function that is used in.image.nvim
. Let me know if it would be better placed in another location in the project or if it is better to use other implementation (I'm not very familiar with the lua ecosystem)EDIT:
Point 3 is no longer part of this PR, as @benlubas correctly pointed out that the performance problems that I was experiencing with OnCursorMove only apply when you don't set the
conceal
option, I keep the text here for context:3. Remove the "OnCursorMove" event handling. Unfortunately it is too costly whenever you have more than 5 or 6 equations on screen. If you try to open a document with ~10 equations like in the example you can end up with the nvim ui effectively locked if you try to move your cursor too quickly. In addition this event does not prevent the user from having to re-run
latex_render
if they are making modifications to the equations, as new equations won't get rendered on OnCursorMove event. I think it is better to just make the user re-runlatex_render
, but I'm open to revert this change if you consider it's still better to have the event as it is onmain
.