Skip to content

Optimize session loading performance by debouncing heavy UI updates#1142

Open
rainux wants to merge 1 commit intoqvacua:masterfrom
rainux:optimize_session_loading
Open

Optimize session loading performance by debouncing heavy UI updates#1142
rainux wants to merge 1 commit intoqvacua:masterfrom
rainux:optimize_session_loading

Conversation

@rainux
Copy link
Contributor

@rainux rainux commented Dec 3, 2025

Startify session loading triggers a storm of RPC events (bufferListChanged, refreshFileBrowser, etc.) from Neovim. Previously, VimR responded to each event individually, causing excessive RPC calls (e.g., fetching all buffers) and UI updates (File Browser refresh), resulting in severe lag.

This commit implements a debouncing strategy to coalesce these frequent, heavy updates:

  1. Introduces uiSyncSubject in MainWindow to debounce heavy update requests with a 200ms interval.
  2. Redirects bufferListChanged, cwdChanged, bufferWritten, refreshFileBrowser, and revealCurrentBufferInFileBrowser to this debouncer.
  3. Implements syncUiWithNvim to perform a single, batched update of the buffer list, CWD, and File Browser state after the debounce interval.
  4. Keeps newCurrentBuffer and tabChanged as direct, non-debounced updates to ensure immediate UI responsiveness (e.g., window title, tab bar) during manual interactions.

This significantly improves session loading speed while maintaining a responsive UI for daily usage.

Implemented by Gemini CLI.

Startify session loading triggers a storm of RPC events (bufferListChanged, refreshFileBrowser, etc.) from Neovim.
Previously, VimR responded to each event individually, causing excessive RPC calls (e.g., fetching all buffers) and UI updates (File Browser refresh), resulting in severe lag.

This commit implements a debouncing strategy to coalesce these frequent, heavy updates:
1. Introduces `uiSyncSubject` in `MainWindow` to debounce heavy update requests with a 200ms interval.
2. Redirects `bufferListChanged`, `cwdChanged`, `bufferWritten`, `refreshFileBrowser`, and `revealCurrentBufferInFileBrowser` to this debouncer.
3. Implements `syncUiWithNvim` to perform a single, batched update of the buffer list, CWD, and File Browser state after the debounce interval.
4. Keeps `newCurrentBuffer` and `tabChanged` as direct, non-debounced updates to ensure immediate UI responsiveness (e.g., window title, tab bar) during manual interactions.

This significantly improves session loading speed while maintaining a responsive UI for daily usage.

Co-authored-by: Gemini <gemini@google.com>
@qvacua
Copy link
Owner

qvacua commented Dec 22, 2025

Do you mean https://github.com/mhinz/vim-startify? I tried it and, afaics, only one buffer list changed event fires when I open a new window. Maybe it's something else which triggers the events?

@rainux
Copy link
Contributor Author

rainux commented Dec 23, 2025

Sorry, I forgot to explain it clearly. This happens in a tab-based work flow:

  1. Install the vim-startify plugin.
  2. Open multiple files in tabs, with one file per tab.
  3. Use the :SSave command provided by vim-startify to create a session.
  4. Restart VimR and select this session from the vim-startify start page.

Before this PR, step 4 would cause VimR to freeze for several seconds, while the original Neovim loads the same session instantly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants