Skip to content

Stop the workspace row rebuilding itself for no visible change - #9440

Closed
VykosMolt wants to merge 1 commit into
omacom:quattrofrom
VykosMolt:perf/workspace-row-rebuild
Closed

VykosMolt wants to merge 1 commit into
omacom:quattrofrom
VykosMolt:perf/workspace-row-rebuild

Conversation

@VykosMolt

@VykosMolt VykosMolt commented Aug 31, 2026 •

Copy link
Copy Markdown

Creating or leaving an empty workspace rebuilds the whole workspace row, even when the visible IDs have not changed. The row always includes workspaces 1–5, but workspaceIds() returns a new array whenever Hyprland's workspace list changes. Repeater treats that as a new model and replaces every delegate. columns calls the function again.

The row now keeps the same array until its IDs change. Creating workspace 4 leaves [1,2,3,4,5] intact; creating a workspace outside that range replaces it. A map built once per update also replaces the lookup each delegate used to perform over the workspace list.

The ID and lookup logic lives in WorkspacesModel.js, following the existing model modules so it can run under Node. workspaces-model-test.sh checks the fixed 1–5 range, additional workspaces arriving and leaving, invalid entries, and array identity. It also checks that different IDs with the same length are treated as a change and that the QML uses the stable array and lookup map. The test fails on the baseline, which has no model module.

./test/shell passed 218 of 222 files. The four failures (config-test, runtime-smoke-test, snapper-test, and unowned-system-paths-test) also failed on unmodified quattro.

This touches Workspaces.qml alongside #9419's click-dispatch change, so whichever lands second may need rebasing.

A Repeater compares its model by identity, not by contents: hand it a new array
and it destroys every delegate and builds them again, however alike the two
arrays are. The row's model was `root.workspaceIds()`, a function call in a
binding that allocated a fresh array every time it ran, and it re-ran whenever
Hyprland's workspace list changed. `columns:` called the same function a second
time.

Hyprland's workspace list changes when a workspace is created or destroyed,
which is what happens the moment you touch an empty one. Moving between
workspaces that hold windows changes nothing and is smooth. Pressing SUPER+4
from an occupied workspace created 4 and rebuilt the whole row, and leaving 4
empty destroyed it and rebuilt the row again. That is why the stutter came and
went rather than being there every time.

The waste is worse than it first looks. The row always offers 1 through 5, so
creating workspace 4 does not change what it draws at all: the ids are
[1,2,3,4,5] before and after. Every one of those rebuilds produced an identical
row. It only genuinely changes when a workspace outside 1-5 appears or goes
away.

The ids now live in a property that is replaced only when the ids really differ,
so the array's identity survives a change that does not alter the row.

The delegate's `workspaceById()` went with it. Each delegate scanned the whole
workspace list to find its own workspace, which made drawing the row O(n^2)
every time it was rebuilt. The map is now built once per change.

The model math moved to WorkspacesModel.js, matching MenuModel.js and
NightlightModel.js, so it can be unit tested under node. It also holds a
workspace list more defensively than the inline version did: a null entry in
Hyprland.workspaces.values used to throw reading `.id`, and a non-numeric id
used to be pushed into the row.
@bjarneo

bjarneo commented Sep 21, 2026

Copy link
Copy Markdown
Member

Automated duplication check: this pull request looks similar to #8794, which covers the same workspace Repeater stability. I keep that one open and close this one to consolidate review.

If you feel this is the wrong decision, please open the PR again with a note on the difference.

@bjarneo bjarneo closed this Sep 21, 2026
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