[perf] Linux: every workspace switch and sidebar hover re-crawls the whole worktree (bursts to 377k inotify watches)
Where did this happen?
Other (Linux desktop app, AppImage)
Version
1.30.2 Measured against a build of main at 2370f60d4 (includes #7860 and #7865).
What happened?
On a Linux monorepo, switching between workspaces and hovering workspaces in the sidebar keeps the host service busy re-crawling whole worktrees. Each monorepo worktree is ~23.3k inotify watches (~5.4k directories + ~17.9k files, since the chokidar backend watches both). The host service spends a lot of its time above one core, and the watch count bursts to hundreds of thousands.
Two causes, both still present on current main:
Every switch disposes the watcher and the next switch re-crawls it. FsWatcherManager.subscribe() disposes a root's watcher the moment its last listener goes (packages/workspace-fs/src/watch.ts). useWorkspaceEvent("fs:events", …) re-runs its effect on workspaceId, so switching away sends fs:unwatch, and switching back attaches and crawls the whole tree again. When switches come faster than disposal, the crawls stack. We measured bursts of up to 377k watches.
Hovering a workspace in the sidebar attaches a recursive watch of that worktree. DashboardSidebarHoverCardOverlay calls useDiffStats(hoveredId), which subscribes to git:changed. That makes GitWatcher attach a recursive root watch for the hovered workspace, just to show the card's two diff numbers. With the watch count as the signal, hovering alone added 6–26k watches per sweep, and once 287k.
This is different from #6729 (which workspaces GitWatcher watches) and #4198 / #6004 (how often git runs, and what each call costs). It also isn't covered by #7865, which moved scans off the terminal event loop (responsiveness), or #7860 (ignore-matching cost). Neither changes how much gets watched, or how often it is re-crawled.
Steps to reproduce
- On Linux, open a large repo (ours: ~17.9k tracked files) with 3+ worktrees as Superset workspaces.
- Watch the host service's inotify count:
for fd in /proc/<host-service pid>/fdinfo/*; do grep -c '^inotify' $fd; done | paste -sd+ | bc. - Switch between two of those workspaces every ~20 s. Each switch drops the count and re-crawls about 23k watches, at 150–400% host-service CPU. Faster switching stacks the crawls.
- Hover the sidebar rows of workspaces that aren't open, holding each until its card shows. The count climbs while hovering.
Logs, screenshots, or recordings
Controlled A/B on one machine (Linux container on a Proxmox VM, RTX 2060). Each arm ran a freshly restarted app. Two builds of main at 2370f60d4, packaged identically: control (no changes), and fixed, which is the same commit plus the two linked PRs and two small ignored-dir listing changes. Those two had no observable effect in this run and aren't proposed yet. Both ran the same scripted 30-minute workload: 88 deep-link workspace switches every 20 s (80 warm across 3 monorepo worktrees, 8 cold), plus 6 sidebar hover sweeps over 6 workspaces. The sweeps drove the real pointer through XTest, and every card was confirmed by screenshot. Samples were taken every 5 s: per-process CPU from /proc, and inotify watches from /proc/<pid>/fdinfo.
| control | fixed | change | |
|---|---|---|---|
| Superset CPU total (core-seconds per hour) | 4472 | 2900 | −35% |
| host service incl. git | 3466 | 1878 | −46% |
| host service above one core | 43% of samples | 20% | |
| inotify watches p50 / max | 23k / 377k | 68k / 97k | |
| watches added by hovering alone | 6–26k per sweep, once 287k | 0 |
The fixed build's median watch count is higher on purpose: it keeps up to 3 recently used workspaces attached, instead of re-crawling them on every switch.
Fixes proposed in:
- keep-alive: #7878
- hover card: #7879
Source: superset-sh/superset