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
perf: cache diagnostics, fire mode events less often (#115)
* ref: separate updating the diagnostics and applying virtual text
When checking some lags I had, `tiny-inline-diagnostic` seemed to be the
main culprit, and more precisely the number of call to
`vim.diagnostic.get`. This introduces a cache for the diagnostics to
avoid that call, separating updating the data and displaying it.
* feat: prevents triggering USER_EVENT on every mode change
The mode can change *a lot* in a short period of time (several times in
a second when doing a surround with mini.ai for instance). The issue is
that we were calling `enable` each time the mode changed, which
triggered the `USER_EVENT` events and in particular the
`apply_virtual_texts` function. This led to a lot of unnecessary
computation and redraw of the diagnostics, in turn making Neovim laggy,
especially in the presence of many diagnostics.
We instead only fire the event if we were disabled. If the text or the
position of the cursor has changed, the other events
(`DiagnosticChanged`, `CursorMoved`, ..) should take care of updating
the diagnostics and the virtual text.
* fix: prevent diag source to be appended multiple times to message
* fix: don't overwrite the diagnostics from other sources
When using multiple sources, the diagnostics coming from
`DiagnosticChanged` can be multiple and disjoint if coming from
different sources. We thus need to overwrite only the diagnostics of the
incoming source.
* ref: filter diags at write time rather than read time
The assumption is that writing happens less often than reading and
because of that we chose to keep a single array to read with all the
diagnostics instead of one array per buffer and per source and having to
create a new concatenated table each time we read them.
To get the best of both world we could:
- Have some kind of nested iterators that goes through each source and
array. This would be problematic though if we need to sort the data
between the two sources.
- Have a separate cache for the concatenated version of the diagnostics
that's populated at read time and then re-used and cleared at write
time.
* fix: diagnostics not cleared when they should
When we get an empty array in the `DiagnosticChanged` events, it means
that one of the namespace has been cleared. The problem is that we don't
(and can't) know which one it was without calling `vim.diagnostic.get`
to get all the diagnostics.
0 commit comments