[Bug]: Rapid tab switching stalls for 1.3-1.6s — redundant per-switch DB reloads serialize on the single-connection store

Aperta
#3,422 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
go

Direzione di ricerca

Start with reinitWave and WorkspaceService.SetActiveTab, then compare the two linked fork commits to understand the reduced reloads, removed return-value reads, and cache-resync tradeoff. Reproduce rapid switching on Windows and profile SetActiveTab; done means no queued per-switch reload spikes and switching remains near the reported low-millisecond results.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Current Behavior

Switching tabs quickly (clicking through 3+ tabs, or holding the switch-tab shortcut) intermittently freezes the UI for 1.3–1.6 seconds. Single, slow-paced switches feel fine; the stall appears once switches come in quick succession, and it gets worse with more tabs/blocks in the workspace. Observed on Windows; the mechanism below is platform-independent, but slower disk I/O (NTFS + Defender) makes it much more visible there.

Expected Behavior

Tab switching stays in the low-milliseconds range regardless of how fast you switch or how many tabs the workspace has.

Steps To Reproduce
  1. Windows 11, Wave with one workspace containing ~5+ tabs, each with a few terminal blocks
  2. Rapidly switch between tabs (click tabs in quick succession or repeat the tab-switch keybinding)
  3. UI stalls for over a second; profiling the backend shows SetActiveTab spiking to ~1.5s
Wave Version

v0.14.5 (also reproduced on recent main)

Platform

Windows

OS Version/Distribution

Windows 11

Architecture

x64

Anything else?

I profiled this and the cost is not the WebContentsView swap (setBounds is ~0.1ms) — it's a flood of DB operations triggered on every switch, all serialized on the single-connection store:

  1. reinitWave reloads everything on each switch: client, window, workspace, the switched-to tab, its layout, plus every other tab in the workspace — N+5 DB reads per switch. These are almost entirely redundant: the tab's webContents stays alive off-screen with live WPS subscriptions, so its cache is already fresh.
  2. WorkspaceService.SetActiveTab reads the tab and all of its blocks to build a return value that no caller consumes (the frontend signature is already Promise<void>).

Under rapid switching these reads queue up on the store and everything behind them waits.

Measured results after fixing both (reloading only the switched-to tab + layout as a safety net, and dropping the unused return-value reads):

  • SetActiveTab backend time: max 1576ms → ~20ms (zero spikes >100ms)
  • Switch median: 16ms → 6.4ms

Working fix in my fork:

Two design points worth flagging if you want this upstreamed:

  • The follow-up uses a 30s-throttled background resync as the stale-cache safety net; an alternative (arguably cleaner) is resync-on-reconnect in wos.ts, which didn't exist as a hook when I wrote this.
  • Removing SetActiveTab's return value is a service-contract change; I verified the only caller discards it, but calling it out explicitly.

Happy to open a PR with the fix if this direction works for you.

Lingua principale
Go
Stelle
22.7k
Fork
1.2k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di wavetermdev/waveterm

Tutte le issue di wavetermdev/waveterm

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.