Skip to content

internal/ui: rebuild the sidebar once per peer update, not once per page - #357

Open
horststaley wants to merge 1 commit into
DeedleFake:masterfrom
horststaley:sidebar-hold
Open

horststaley wants to merge 1 commit into
DeedleFake:masterfrom
horststaley:sidebar-hold

Conversation

@horststaley

Copy link
Copy Markdown

Fixes #102.

AdwViewSwitcherSidebar connects the stack's items-changed and sections-changed signals to repopulate_sidebar(), which removes and recreates every row. MainWindow adds and removes stack pages one at a time, so with n peers:

  • Opening the window adds n pages, and then restack() removes and re-adds all of them because the first order comes from map iteration. That's about 3n full sidebar rebuilds, or O(n²) row constructions.
  • Any later change to the sidebar's order, such as a peer going online or offline, a search keystroke, or toggling offline peers, restacks everything again: about 2n rebuilds while the window is open.

This adds holdSidebar, which unsets the sidebar's stack while updatePeers, updatePages, and applyLayout change the stack's pages and sets it again afterwards, so the sidebar is rebuilt once per update. Holds nest. The sidebar is only detached when an update actually adds, removes, or reorders pages, so polls that change nothing don't touch it.

Measured with a 178-peer tailnet in the GNOME 51 Flatpak runtime with software rendering. Main-thread CPU time per window open from the tray icon:

Build Before After
v0.21.0 5.5 s 0.85–1.0 s
master (67266aa) 5.8 s 0.85–1.0 s

On v0.21.0, MainWindow.Update on first open went from 4.9 s to 0.25–0.3 s, and restack() from 3.1 s to 25 ms. With the window open, toggling offline peers went from 2.4–2.9 s of CPU to 0.2–0.4 s. Most of what remains on open is GTK's first layout and paint.

TestPeerUpdatesDontRebuildSidebar runs 200 peers through updatePeers and counts stack changes made while the sidebar is attached. Without this change it counts 601 for the first update, 402 when one peer goes offline, and 101 when half the peers leave, and takes 10 s. With it, it counts 0 and takes 0.3 s.

Tested inside the GNOME 51 runtime under Xephyr: go test -race passes for all ten packages with tests. go vet and go fix -diff are clean, and go tool golangci-lint run --disable=errcheck reports 0 issues.

🤖 Generated with Claude Code

@horststaley

Copy link
Copy Markdown
Author

No rush, just checking in. This and #356 conflict in mainwindow.go, so if you'd like to land #356 first, I'll rebase this once it's in. The CI run is also waiting for your approval, since this is my first PR here.

@DeedleFake

Copy link
Copy Markdown
Owner

Sorry, I've been a bit tied up with some other things, but I'll try to get to this as soon as I can.

@DeedleFake DeedleFake self-assigned this Nov 8, 2026
@horststaley

Copy link
Copy Markdown
Author

Thanks, and no worries. The exit node selection failure isn't from this PR: the v1.8.0 tla2tools jar was replaced on Nov 6, so its sha256 no longer matches the pin in check-exit-node-selection. a0fe4a9 on poller-push already moves it to 1.7.4, so it should clear up once #356 is in, and I'll rebase this then.

AdwViewSwitcherSidebar rebuilds all of its rows whenever the stack's
pages change, and MainWindow adds and removes pages one at a time, so
opening the window with n peers took O(n²) row constructions. Detach
the sidebar while an update adds, removes, or reorders pages.

Fixes DeedleFake#102.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

very long node list takes a long time to load

2 participants