Skip to content

Show the menu before its guard batch runs, cutting open time from ~140 ms to ~40 ms on laptops - #16784

Open
hegjon wants to merge 4 commits into
omacom:quattrofrom
hegjon:menu-open-work-after-reveal
Open

hegjon wants to merge 4 commits into
omacom:quattrofrom
hegjon:menu-open-work-after-reveal

Conversation

@hegjon

@hegjon hegjon commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Opening the Omarchy menu took 131-158 ms on a ThinkPad T550 (i5-5300U, 2 cores) from the keypress to a mapped layer, where a panel on the same OverlayWindow maps in ~30 ms. The desktop this was first noticed on took ~27 ms, which is why it was easy to miss.

Cause. openExistingMenu() ran the guard batch and the icon rescan itself. The batch is one login bash with the shipped menu's 275 when:/checked:/disabled: guards in eight subshells: ~150 processes and ~0.7 s of CPU on that machine, standalone and idle. Started from the open path, it competes with the first frame for the cores: the main thread's next event-loop turn came 120 ms late in half the opens, and the render thread and the compositor starved with it. Building the 52 KB script cost another 17 ms of main-thread JS before opened = true could take effect. Traced with perf trace and strace: quickshell forks the batch at +0 ms, is busy or starved until +75 ms, creates the window and its render thread from +75 to +131 ms, and the layer maps at ~+135 ms. The icon find over 7335 files adds ~5-10 ms.

Fix. The menu already opens on the previous batch's answers (#15049), so both wait until the card is on screen.

  • scheduleOpenWork() replaces the two calls in openExistingMenu(). A Timer runs evaluateGuards() and refreshIcons() 50 ms after OverlayWindow's contentRevealed (one frame, so the processes never land on the frame that first shows the card), or after 500 ms if the window never reveals. Closing before then cancels the work; a menu opened onto an already revealed window waits the 50 ms only.
  • The guard script is built once per item set and cached: root.items is replaced whole on every rebuild and never edited in place, so the object's identity is the key.
  • The batch runs under nice -n 10, so it yields to the shell, the compositor and whatever the user runs.
  • The rescan still runs on every open, as Run the menu's guard batch once at startup, not once per menu file #15048 decided, only later.

test/shell.d/menu-open-work-test.sh covers the scheduling (fallback vs. reveal, cancel on close, run-once), the script cache and the batch command, in the same body-extraction style as overlay-window-test.sh.

Timing

T550, hyprctl dispatch to Hyprland's openlayer event, six opens each, hypoland compositor, omarchy-dev r7218 (the open path is identical to r7338/quattro tip):

Menu.qml dispatch -> layer mapped open() JS guard answers land
quattro tip 131-158 ms 22 ms (17 in evaluateGuards) ~0.39 s after open
no guard batch on open (experiment) 42-53 ms 5 ms
no batch, no rescan (experiment) 38-47 ms 4 ms
this branch 37-47 ms 0-6 ms ~0.40 s after open

Same measurement on the rest of the fleet, stock then this branch, six opens each, with the compositor each machine ran at the time (the test laptops run Hypoland, a Hyprland fork; the desktop stock Hyprland):

Machine Compositor Stock This branch
Desktop, Ryzen 9 Hyprland 0.56.2 ~27 ms 14-17 ms
ThinkPad T550, i5-5300U (2c) Hypoland r725 106-159 ms 38-47 ms
ThinkPad T550, same machine Hyprland 0.56.2 107-184 ms 39-47 ms
Dell XPS 13 9343, i5-5200U (2c), scale 2 Hypoland r725 127-169 ms 44-63 ms
ThinkPad T460s, i5-6300U (2c), scale 1.5 Hypoland r725 115-161 ms 38-44 ms
ThinkPad X200, Core 2 Duo, GM45 Hypoland r748 272-374 ms 72-93 ms
Galaxy Book4 Edge, Snapdragon X Elite (12c), aarch64, omarchy 4.5.0rc1 Hypoland r725 61-78 ms 40-62 ms
Dell Chromebook 11 3120, Celeron N2840 (2c) Hypoland r752 586-816 ms 122-140 ms
Dell Chromebook 11 3120, same machine Hyprland 0.56.2 502-704 ms 129-141 ms

Measured from the open, the batch starts about 80 ms later on the two-core Broadwell/Skylake laptops and the desktops, 105-135 ms on the X200 and 145-170 ms on the Chromebook; its answers land about 0.4 s after the open on the two-core laptops (0.39 s with the batch on the open path), 0.25 s on the Galaxy Book, 0.95 s on the X200 and 1.4 s on the Chromebook, under nice -n 10.

perf record over three stock opens, children inherited: quickshell 12 %, its render thread 5 %, child processes 83 % (find 12, bash 11, pgrep 5, hyprctl 5, jq 5, ...).

Verification

  • menu-test.sh, menu-guards-test.sh, menu-guard-budget-test.sh, overlay-window-test.sh and the new menu-open-work-test.sh pass.
  • qmllint adds one unqualified warning for onContentRevealedChanged: if (contentRevealed && ...), the same form as the onShownChanged line above it; no new errors.
  • Live on the T550 with timing logs: the batch starts ~80 ms after the open at niceness 10, all 276 guard lines still land, no QML warnings from the menu in the journal. The package file was restored afterwards.
  • Live on seven more machines (x86_64 two-core laptops, a Ryzen 9 desktop on stock Hyprland, an aarch64 Galaxy Book on omarchy 4.5.0rc1, a Bay Trail Chromebook), stock then patched, with the package file restored afterwards; no QML warnings from the menu, guard answers land on every open.

Tooling

The investigation (perf, strace, the Hyprland event-socket harness), the patch, the test and the fleet measurements were done with Claude Code running Claude Fable 5.1 (claude-fable-5-1) at reasoning effort 80, directed and reviewed by the author in one session on 2026-10-27.

🤖 Generated with Claude Code

Every menu open ran the guard batch and the icon rescan from the open
path: one login bash with the shipped menu's 275 when/checked/disabled
guards in eight subshells, ~150 processes and ~0.7 s of CPU on a two-core
laptop, plus a find over every icon directory. Started there, they compete
with the first frame for the cores. On a ThinkPad T550 (i5-5300U) the menu
took 131-158 ms from the keypress to a mapped layer, and 42-53 ms with the
batch left out; a panel on the same OverlayWindow maps in ~30 ms. Building
the 52 KB script was another 17 ms of main-thread JS before the window
could show.

The menu already opens on the previous batch's answers, so both now wait
until the window has revealed its content plus one frame (50 ms after
OverlayWindow's contentRevealed, 500 ms if it never reveals), and a menu
closed before then runs neither. The script is built once per item set,
since items are replaced whole and never edited in place. The batch runs
under nice -n 10, so it also yields to the compositor and whatever the user
is doing. The rescan still runs on every open, as omacom#15048 left it, only
later.

T550, dispatch to Hyprland's openlayer event, six opens: 37-47 ms, from
131-158. The batch starts ~80 ms after the open and its answers land ~0.4 s
after it, as before.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

The menu now shows its card before starting the guard batch and icon scan.

  • The menu shows its card before running guard checks and icon scans.

No new actionable issues were found. The three earlier concerns are addressed. Tests were not run during this review.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Open menu] --> B[Show previous answers]
  B --> C[Start 500 ms fallback]
  C --> D{What happens first?}
  D -->|Card reveals| E[Wait 50 ms]
  D -->|Fallback expires| F[Run guards and scan icons]
  E --> F
  D -->|Menu closes| G[Cancel pending work]
  E -->|Menu closes| G
Loading

Reviews (4) · Last reviewed commit: "Merge remote-tracking branch 'origin/qua..." · Reviewed by Greptile

Comment thread test/shell.d/menu-open-work-test.sh Resolved
Comment thread test/shell.d/menu-open-work-test.sh Resolved
@hegjon hegjon changed the title Open the menu before running its guard batch Show the menu before its guard batch runs, cutting open time from ~140 ms to ~40 ms on laptops Oct 27, 2026
…ch in docs/menu.md

The review pointed at AGENTS.md: the menu's tests live in menu-test.sh and
menu-guards-test.sh, not in a new file, and a test must not restate the
implementation. The separate file is gone and its checks on the text of
openExistingMenu with it; what remains in menu-test.sh exercises the
scheduling (fallback versus reveal, run once, cancel on close) and the
guard script cache through the extracted functions, and fails on the base
branch. docs/menu.md's guard section now says the batch starts once the
card is on screen.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Comment thread docs/menu.md Resolved
@greptile-apps

greptile-apps Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Want your agent to iterate on Greptile's feedback? Try greploops.

AGENTS.md asks for full lines in Markdown, breaking only at structural
boundaries; the paragraph the previous commit edited was still wrapped.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@omarchybot

Copy link
Copy Markdown
Collaborator

Thanks, @hegjon. This one has been read but not yet reviewed or run, because the two models classifying it disagree on what it is, and the kind decides how it is verified.

Claude Opus 5.5 read it as an enhancement: the menu opens and works on quattro today, and this makes it open faster by moving the guard batch and icon rescan until after the card is shown. Codex Medium, asked separately from the diff alone, read it as a bug: a 100-170 ms delay on two-core laptops (and up to ~800 ms on the Chromebook in your table) caused by the open path forking ~150 processes is behaviour that is wrong as shipped.

No class label has been added, and nothing was run on a worker. It is waiting on the maintainer to settle which it is; once that is decided it will be reviewed and tested on that basis.

@hegjon

hegjon commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

This is an enhancement: nothing is broken on quattro, the menu just opens slower than it needs to on low-core machines. Verify it by timing the open on base vs. this branch (the tables above) and checking the guard answers still land.

If fresh numbers would help, I'll follow up with a new measurement run.

@hegjon

hegjon commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

New numbers from the lab machines. The branch is merged with quattro (ae64a4b); Menu.qml on quattro has not changed since this PR was opened, so the patched file measured is byte-identical to this branch's.

Same measurement as in the description: hyprctl dispatch of the menu shortcut to Hyprland's openlayer event. Each machine got a fresh SDDM session per compositor and alternated stock and patched twice, 12 opens each; stock Hyprland 0.57.0 and Hypoland (a Hyprland fork) on every machine, the X200 Hypoland only.

Open time in ms, range (median):

Machine Compositor Stock This branch Speed-up Guard answers land
ThinkPad T550, i5-5300U (2c) Hypoland r934 92-192 (152) 38-56 (40) 3.8x ~0.43 s
Hyprland 0.57.0 120-206 (164) 40-49 (42) 4.0x ~0.43 s
Dell XPS 13 9343, i5-5200U (2c), scale 2 Hypoland r934 142-203 (173) 46-71 (50) 3.5x ~0.40 s
Hyprland 0.57.0 135-251 (207) 51-76 (64) 3.2x ~0.40 s
ThinkPad T460s, i5-6300U (2c), scale 1.5 Hypoland r934 110-155 (139) 37-56 (41) 3.4x ~0.48 s
Hyprland 0.57.0 115-194 (160) 39-52 (43) 3.8x ~0.48 s
Samsung Series 7, i5-3337U (2c) Hypoland r934 190-215 (204) 52-71 (55) 3.7x ~0.48 s
Hyprland 0.57.0 168-334 (241) 55-100 (67) 3.6x ~0.48 s
ThinkPad T490, i5-8265U (4c) Hypoland r933 62-77 (72) 28-33 (30) 2.4x ~0.22 s
Hyprland 0.57.0 70-85 (79) 28-36 (30) 2.6x ~0.22 s
Desktop, AMD A8-6600K (4c), Radeon HD 8570D Hypoland r934 119-198 (164) 49-68 (60) 2.7x ~0.39 s
Hyprland 0.57.0 122-202 (165) 50-64 (55) 3.0x ~0.38 s
ThinkPad X200, Core 2 Duo, GM45 Hypoland r941 241-414 (~330) 76-91 (78) 4.2x ~0.92 s
Dell Chromebook 11 3120, Celeron N2840 (2c) Hypoland r934 255-695 (581) 116-159 (125) 4.6x ~1.35 s
Hyprland 0.57.0 497-1368 (648) 119-174 (130) 5.0x ~1.32 s
Galaxy Book4 Edge, Snapdragon X Elite (12c), aarch64 Hypoland r936 66-102 (72) 44-115 (51) 1.4x ~0.31 s
Hyprland 0.57.0 65-96 (72) 42-132 (50) 1.4x ~0.32 s
Mac mini M1, aarch64 (Asahi) Hypoland r937 61-89 (84) 39-63 (50) 1.7x ~0.21 s
Hyprland 0.57.0 70-98 (83) 39-64 (46) 1.8x ~0.21 s
  • The compositor makes little difference: the time goes to the guard batch forking on the open path, under either one.
  • Guard answers landed on every open on every machine. The batch starts 70-100 ms after the open (about 110 ms on the X200 and 145 ms on the Chromebook), and the journal has no menu QML warnings.
  • On the Galaxy Book the first open after a shell restart was 111-132 ms with this branch, both times and under both compositors; every later open was 42-62 ms.
  • Omarchy on the machines: omarchy-dev r7438 to r7569, and omarchy 4.5.0rc2 on the Galaxy Book.

Measured on 2026-11-03 with Claude Code running Claude Opus 5.5 (claude-opus-5-5), directed and reviewed by the author.

@hegjon

hegjon commented Nov 10, 2026

Copy link
Copy Markdown
Contributor Author

As a shower tough, would it be possible to generate the menu entries ahead of time? Either the whole menu or parts of it?

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants