Repository navigation
Show the menu before its guard batch runs, cutting open time from ~140 ms to ~40 ms on laptops #16784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hegjon
wants to merge
4
commits into
omacom:quattro
Choose a base branch
from
hegjon:menu-open-work-after-reveal
base: quattro
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+124
−13
Open
Show the menu before its guard batch runs, cutting open time from ~140 ms to ~40 ms on laptops #16784
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
37bcfc0
Open the menu before running its guard batch
hegjon 02a639c
Fold the open-work checks into menu-test.sh and note the deferred bat…
hegjon 05b3590
Put the guard paragraph in docs/menu.md on one line
hegjon d1e2ad8
Merge remote-tracking branch 'origin/quattro' into menu-open-work-aft…
hegjon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" | ||
|
|
||
| run_node_test <<'JS' | ||
| const fs = require('fs') | ||
| const menuQml = fs.readFileSync(path.join(root, 'shell/plugins/menu/Menu.qml'), 'utf8') | ||
| const body = (pattern) => { | ||
| const match = pattern.exec(menuQml) | ||
| assert(match, `Menu.qml defines ${pattern}`) | ||
| return match[1] | ||
| } | ||
|
|
||
| // The open path shows the card first; the guard batch and the icon rescan, | ||
| // which together fork ~150 processes, follow once the card is on screen. | ||
| const openBody = body(/function openExistingMenu\(initialMenu\) \{([\s\S]*?)\n \}/) | ||
| assert(!/evaluateGuards\(\)/.test(openBody), 'opening a menu does not start the guard batch itself') | ||
| assert(!/refreshIcons\(\)/.test(openBody), 'opening a menu does not start the icon rescan itself') | ||
| assert(/opened = true[\s\S]*scheduleOpenWork\(\)/.test(openBody), 'opening a menu schedules both once it is open') | ||
|
greptile-apps[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| const afterReveal = Number(body(/readonly property int afterReveal: (\d+)/)) | ||
| const fallback = Number(body(/readonly property int fallback: (\d+)/)) | ||
| assert(afterReveal > 0 && afterReveal < fallback, 'the reveal delay is short and the fallback longer') | ||
|
|
||
| const schedule = new Function('root', 'panel', 'openWorkTimer', body(/function scheduleOpenWork\(\) \{([\s\S]*?)\n \}/)) | ||
| const cancel = new Function('root', 'openWorkTimer', body(/function cancelOpenWork\(\) \{([\s\S]*?)\n \}/)) | ||
| const run = new Function('root', 'openWorkTimer', body(/function runOpenWork\(\) \{([\s\S]*?)\n \}/)) | ||
| const revealed = new Function('contentRevealed', 'root', 'openWorkTimer', | ||
| body(/onContentRevealedChanged: (if \(contentRevealed && root\.openWorkPending\) \{[\s\S]*?\n \})/)) | ||
|
|
||
| const timer = () => ({ afterReveal, fallback, interval: 0, running: false, restarts: 0, | ||
| restart() { this.running = true; this.restarts++ }, stop() { this.running = false } }) | ||
| const shell = () => { | ||
| const r = { opened: true, openWorkPending: false, guards: 0, icons: 0, | ||
| evaluateGuards() { r.guards++ }, appLibrary: { refreshIcons() { r.icons++ } } } | ||
| return r | ||
| } | ||
|
|
||
| let fake = shell(), t = timer() | ||
| schedule(fake, { contentRevealed: false }, t) | ||
| assert(fake.openWorkPending && t.running, 'scheduling arms the timer') | ||
| assertEqual(t.interval, fallback, 'a window that has not revealed waits on the fallback') | ||
| revealed(true, fake, t) | ||
| assertEqual(t.interval, afterReveal, 'the reveal shortens the wait to one frame after it') | ||
| assertEqual(t.restarts, 2, 'the reveal restarts the timer') | ||
| run(fake, t) | ||
| assertDeepEqual([fake.guards, fake.icons, t.running, fake.openWorkPending], [1, 1, false, false], | ||
| 'the timer runs the guard batch and the icon rescan once, then disarms') | ||
| run(fake, t) | ||
| assertEqual(fake.guards, 1, 'work that already ran does not run again') | ||
|
|
||
| fake = shell(); t = timer() | ||
| schedule(fake, { contentRevealed: true }, t) | ||
| assertEqual(t.interval, afterReveal, 'opening onto an already revealed window waits one frame only') | ||
| revealed(false, fake, t) | ||
| assertEqual(t.restarts, 1, 'losing the reveal does not touch the timer') | ||
|
|
||
| fake = shell(); t = timer() | ||
| schedule(fake, { contentRevealed: false }, t) | ||
| fake.opened = false | ||
| cancel(fake, t) | ||
| assert(!t.running && !fake.openWorkPending, 'closing cancels work that has not started') | ||
| run(fake, t) | ||
| assertEqual(fake.guards, 0, 'a cancelled open runs nothing') | ||
|
|
||
| fake = shell(); t = timer() | ||
| schedule(fake, { contentRevealed: false }, t) | ||
| fake.opened = false | ||
| run(fake, t) | ||
| assertEqual(fake.guards, 0, 'a menu closed before the timer fires runs nothing') | ||
| assert(!fake.openWorkPending, 'and nothing stays pending for the next open') | ||
|
|
||
| // The guard script only changes with the items, which are replaced whole, | ||
| // so it is built once per item set rather than on every open. | ||
| const evaluate = new Function('root', 'guardProc', 'MenuModel', body(/function evaluateGuards\(\) \{([\s\S]*?)\n \}/)) | ||
| let builds = 0 | ||
| const MenuModel = { guardScript(items) { builds++; return items.script } } | ||
| const itemsA = { script: 'echo a:w:1' } | ||
| fake = { items: itemsA, guardScriptItems: null, guardScript: '', guardsPending: false } | ||
| const guardProc = { running: false, collected: '', command: null } | ||
| // Each run starts the batch; pretend it exited before the next evaluation. | ||
| const evaluateOnce = () => { evaluate(fake, guardProc, MenuModel); guardProc.running = false } | ||
| evaluateOnce() | ||
| evaluateOnce() | ||
| assertEqual(builds, 1, 'the guard script is built once for the same items') | ||
| assertDeepEqual(guardProc.command.slice(0, 5), ['nice', '-n', '10', 'bash', '-lc'], 'the guard batch yields to the shell and the compositor') | ||
| assertEqual(guardProc.command[5], 'echo a:w:1', 'the cached script is what runs') | ||
| fake.items = { script: 'echo b:w:1' } | ||
| evaluateOnce() | ||
| assertEqual(builds, 2, 'replaced items rebuild the guard script') | ||
| assertEqual(guardProc.command[5], 'echo b:w:1', 'the rebuilt script is what runs') | ||
| fake.items = { script: '' } | ||
| evaluateOnce() | ||
| assertDeepEqual(fake.whenResults, {}, 'items without guards clear the answers without running a batch') | ||
| JS | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.