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
## Details
This change speeds up rendering `latex`, especially noticeable when
there are many in the document. This is done by kicking off the jobs to
do the conversion for all formulas in one batch, then waiting for them
all to complete. This relies on the `vim.system` API so requires
`0.10.0`, the old `vim.fn.system` based approach is kept for backwards
compatibility, but will not have any performance improvements.
In order to do this we need access to all the `latex` nodes at one point
in time. This is done by storing them in the buffer level `Context`
module. Then we take advantage of the new `last` parameter given to the
handler to perform rendering for all the nodes. Before we reach `last`
we simply append to the list and return an empty collection of marks.
This will likely complicate debugging efforts in the future as
computations are no longer neatly ordered by the node they are operating
on, but I think this is a reasonable trade off.
Once we start processing the nodes we create all the tasks with
`vim.system`, then await the results of each, reducing the amount we are
blocking as work can continue in the background. The results are stored
in the existing `cache`, while rendering we get the cached value which
should always be available.
The `latex` nodes are retrieved as a list of lists, the initial level
indicates that the following nodes all start on the same row. Currently
this allows us to skip some duplicate work like calculating the `indent`
level which will be the same for all `latex` nodes on the same row. In
general this is a pretty insignificant gain, but still nice. In the
future we can use this to combine virtual lines for multiple formulas to
improve the overall rendering, currently the virtual lines just get
stacked on top of each other.
Semi-related changes:
- update `log_runtime` to limit elapsed time to 10,000 instead of 1,000
- add `copy` method to `Line` module
## Results
On my machine (M2 max) with about 100 formulas on screen to render
looking at the runtime for the initial render.
- default converter (`latex2text`): 1500ms -> 300ms (5x faster)
- faster converter (`utftex`): 225ms -> 85ms (2.5x faster)
0 commit comments