Skip to content

Stop an idle window from drawing every refresh - #100

Merged
dhh merged 3 commits into
omacom:mainfrom
thisisgm:idle
Nov 16, 2026
Merged

dhh merged 3 commits into
omacom:mainfrom
thisisgm:idle

Conversation

@thisisgm

Copy link
Copy Markdown
Contributor

One fix, in one commit with its own test: now and then a Folio window that is doing nothing keeps drawing a frame at every refresh of the screen, with its render thread on about half a core, until it is closed. A race in Qt sets it off, and the cache buffer of Folio's views is what walks into it. The views now make their rows without that buffer. The suite goes from 194 to 197 tests. No library, depends or optdepends entry is added.

What you'd notice

  • An idle window stays idle. A window left open on a folder no longer has a chance of holding half a core and the GPU for as long as it lives, which on a laptop is fan noise and battery.
  • The grid settles sooner on a folder of pictures or videos. At the start it makes thumbnails for fewer rows past the bottom edge: 87 where it made 105, in the window measured below.
  • Nothing else moves. The list and the columns make the same rows as before, and every view draws what it drew.

Numbers

How often it happens depends on timing, so the counts are small and uneven. Measured on a mini PC, cold starts on a folder of 2,000 videos and pictures:

Build Starts Windows that never went idle
0.1.1 24 4
0.1.1 with the cache buffer off 24 0
#26's branch, this week 18 1
main, this week 54 0
Builds with the cache buffer off, this week (18 of them with this commit's settings) 72 0

In each of the four caught on 0.1.1 a probe counted 479 or 480 frames in every 4 seconds on a still, complete window (a 120 Hz screen), for the two minutes it was watched. The one this week used 42.6 s of CPU in the measured window, against about 11 s for its neighbours.

The same folder, thumbnails made anew at each start, page cache dropped, 6 runs a view, main and this branch in one session (the build measured has this commit's view settings; review since then named the 320 and tightened the test):

View First window, main this branch Settled, main this branch CPU, main this branch Memory, main this branch
Grid 906 to 1,007 ms 894 to 1,038 ms 4,533 to 5,194 ms 3,981 to 4,253 ms 18.5 to 19.5 s 16.0 to 16.5 s 156.1 to 163.4 MiB 152.9 to 159.9 MiB
List 853 to 964 ms 892 to 993 ms 2,878 to 3,094 ms 2,966 to 3,226 ms 9.5 to 9.8 s 9.1 to 9.9 s 130.5 to 137.3 MiB 131.1 to 138.0 MiB
Columns 887 to 994 ms 950 to 1,007 ms 2,988 to 3,170 ms 3,058 to 3,365 ms 10.5 to 11.0 s 10.8 to 11.2 s 145.3 to 151.1 MiB 151.8 to 155.6 MiB

On a folder of 100,000 files the two are level in every view: first window 894 to 971 ms against 904 to 959 ms in the grid, memory 235.6 to 236.0 MiB against 229.5 to 240.3 MiB, and the same for the list and the columns.

Holding Down through 300 files in the grid, measured on 0.1.1 with the same change: the time from the key to its frame was 10.3 ms at the median either way, and 13.9 ms at most against 14.9 ms. No frame took longer than one refresh at 60 Hz.

How it works

  • A ListView or GridView with a cache buffer (Qt's default is 320 pixels) fills that buffer later than the rows it shows: each refill starts a 16 ms pause job, bufferPause, in QQuickItemViewPrivate::refill().
  • In QQmlAnimationTimer, a queued stopTimer is skipped while a start is pending. If the pending job is then stopped while it is still in animationsToStart, it is taken off that list and nothing queues another stop. The animation timer stays registered with no job, the animation driver never stops, and the window is redrawn at every refresh. This is Qt Declarative 6.12.0, and the same code is in Qt's dev branch.
  • With cacheBuffer: 0 no pause job is ever started, so the views cannot reach that state.
  • The list and the three lists of the columns get displayMarginBeginning and displayMarginEnd of 320 pixels, which refill() fills at once, with the rows shown and with no timer: the rows that exist are the ones that existed before.
  • The grid gets no margins. A GridView makes a row past each edge by itself, and rows inside a display margin are drawn, not only made: every tile is a layer, and margins there cost 7 MiB on the large folder.

Tests

One new case with a row for each view (grid, list, columns), failing for all three without the commit. It opens the real pane on a folder of 60 entries in a short window, moves the view to its end and back, and checks that in the list and the columns rows reach 320 pixels behind the top edge and as far past the bottom one at once, and that in every view no row is added in the 300 ms after: a cache buffer's timer adds its rows in that time. Eleven mutants, each taking one of the new properties from one view or halving the 320, all fail it.

Limits

  • The columns weigh 3 to 5 MiB more on a folder of thumbnails (the table above), since their margin rows are now drawn. Without margins they would be lighter than main and rows would be made as they scroll in; I kept the rows they had.
  • The race itself is Qt's and is still there for any view that sets a cache buffer. Folio's views no longer do.
  • The counts above say how often it was seen, not how often it will be: it is timing, and main did not show it in this week's 54 starts.

Qt's cache buffer makes them later, from a 16 ms timer of its own, and
a race in Qt can leave that timer running: an idle window then draws a
frame every refresh. The list and the columns make the same rows at
once with display margins; the grid keeps its own row past each edge.
@greptile-apps

greptile-apps Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

The PR disables cache buffers in folder views to avoid repeated drawing while idle. Since the previous review:

  • Folder views skip the cache buffer that can keep idle windows drawing.

No new actionable issues were found.

Reviews (3) · Last reviewed commit: "Keep the lists' settings in one view of ..." · Reviewed by Greptile

@omarchybot omarchybot added bug Something isn't working verified labels Nov 15, 2026
@omarchybot

Copy link
Copy Markdown
Contributor

Reviewed at e8fab78, merged onto current main (bb94499) where it applies cleanly. The bug is real, this fixes its cause, and nothing here needed changing, so nothing was pushed.

What was run, on a throwaway Omarchy VM under Hyprland (Qt 6.12.0, threaded render loop, 75 Hz):

  • bin/build and bin/test: green at this head (197 tests) and with it merged into main.
  • The bug, in Folio's own views. A throwaway test (not pushed) loads the real FolderGrid, FolderList and FolderColumns panes in a window on the compositor, forces the ordering the description gives (an animation finishes, a scroll starts bufferPause, a second refill stops it before startAnimations runs), then counts frameSwapped over 2 s of idle. On main all three panes drew 149 to 151 frames, one per refresh, and the list pane was already drawing about 75 frames a second at startup before anything was forced. With this pull request merged, every pane drew 0, two rounds each. Putting main's three QML files back into the merged tree brought the 150 frames back. Offscreen, which is what CI runs, draws no frames either way, so this check cannot run in the suite.
  • The mechanism, outside Folio. A bare ListView driven through the same ordering drew 374 to 375 frames in 5 s of idle and burned about a second of CPU with the default cache buffer, and drew 0 with cacheBuffer: 0. That matches QQmlAnimationTimer::stopTimer, unregisterAnimation and startAnimations in Qt 6.12's source, and refill() only ever starts bufferPause when buffer is non-zero, so cacheBuffer: 0 removes the trigger rather than hiding it.
  • Plain cold starts on a folder of 2,000 pictures and videos, frames counted 10 to 15 s after launch: 0 idle frames in all 50 starts on main (30 grid, 10 list, 10 columns) and in all 50 with this branch. Like the description's own count for main, this shows the race is rare from a cold start, not that it is gone. The grid requested 19 thumbnails at startup against 25 on main, which is the smaller prefetch the description says it should be.
  • The new test fails on main's view files and passes on this branch's.

Second opinion: Codex at medium effort and muse-wonder (via pi, high thinking) both read the diff against Qt's source. Both confirmed the mechanism and found no defect. These five views are the only ListViews and GridViews in src/, plugins/ has no QML, and nothing that selects, drags, rubber-bands or opens a context menu depends on how many rows exist. Their agreement is not guaranteed to be independent of this review. They raised two points for the maintainer rather than the author:

  • The display margins go beyond the fix. cacheBuffer: 0 by itself is the fix. The 320-pixel margins keep the list and columns making the rows the cache used to make. Unlike cached rows, margin rows are drawn rather than culled, including the rounded thumbnail layers in FileRow.qml. That is where the 3 to 5 MiB the description reports for the columns comes from. Codex would drop the margins and muse-wonder thinks they are a fair trade, so keeping them is a choice, not a defect.
  • The new test checks how rows are made, not idle drawing. It catches the cache buffer coming back in any of the three panes, which is the right thing to guard. It finds views by count > 40, so a small ancestor column is not inspected, though reading the code covers that for this diff.

Overlaps: none of the other open pull requests fixes this. #121 moves the ancestor column's ListView into a Loader, so whichever of the two lands second has to carry cacheBuffer and the margins across. #20 conflicts in FolderGrid.qml, and #55, #21, #18 and #41 conflict with this one in tests/folio_tests.cpp. All of those conflicts are next-door edits, not overlapping changes.

Waiting on: the maintainer. CI ("Build and test") has not run on this fork's branch and needs a maintainer to approve it. Keeping or dropping the display margins is also the maintainer's call.

The cache buffer was the cause. The display margins kept making rows, and starting their thumbnails, ahead of a scroll the way the cache used to, at the cost of drawing those rows. The maintainer asked for the fix as small as it can be, so the views keep just cacheBuffer: 0, with the reason stated once. Without the margins a wheel or fast scroll can show a row's glyph for a frame or two before its thumbnail arrives; the rows themselves are always there.

The test checks every folder view's cache buffer. An idle window draws no frames offscreen, so the redraw itself cannot be seen in the suite; on a compositor, Folio's panes forced through Qt's race drew a frame every refresh on main and none with this.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Codex Medium <noreply@openai.com>
@omarchybot

Copy link
Copy Markdown
Contributor

The maintainer asked for the display margins to go, and for the rest of this pull request to be as simple as it can be. That change is pushed as 6d07db6, on top of your commit.

What changed and why

  • The display margins are gone. cacheBuffer: 0 on the five views is the whole fix. The margins only kept making rows ahead of a scroll the way the cache used to, and those rows were then drawn even though nobody could see them.
  • The reason is written once, in two lines above cacheBuffer: 0 in src/FolderList.qml, and that comment names the grid and the columns. The other four views just set it. rowsPastEdges is gone along with the margins.
  • The test is now a 45-line guard, folderViewsKeepNoCacheBuffer. It opens each pane, finds every list and grid in it (1, 1 and 3), and checks that each has a cache buffer of 0. An idle window draws no frames offscreen, so the suite cannot see the redraw itself. The setting is what decides whether Qt's 16 ms pause can ever start. Removing any one of the five lines fails the test for that pane.

What scrolling looks like without the margins

This ran on a throwaway Omarchy VM under Hyprland, on a folder of 1,800 photos and 200 videos with thumbnails made fresh. For each scroll, every frame counted the rows on screen whose thumbnail had not arrived yet. Three runs each of main, your margins and this head, in the list and the columns:

  • Down key held (every 30 ms): no waiting thumbnails in any of the three.
  • Mouse wheel: with margins and on main, none. Without margins, about 4% of on-screen thumbnail rows showed the glyph for a frame, at most 3 rows at once, and nothing was still waiting when the scroll stopped.
  • Dragging at about 2,500 px/s: with margins and on main, none. Without margins, about 8%, at most 5 rows at once, all filled in about 40 ms after stopping.
  • Dragging at about 6,000 px/s: all three fall behind about equally (around 83%). This head catches up faster (about 225 ms against 345 ms), because it has fewer unseen thumbnails queued.
  • Rows themselves were present in every frame of every run. Only the thumbnail inside a row can arrive a frame or two late, at the leading edge of a wheel or a fast drag.
  • Page Down does nothing in Folio's list or columns, with or without this change, so it is not part of the comparison.

So dropping the margins is slightly worse: at wheel and drag speeds a few rows can show their glyph for a frame or two before the thumbnail appears.

Checked again at 6d07db6

  • The idle fix still holds. Folio's real panes, forced through Qt's race on the compositor, drew 149 to 151 frames in 2 s of idle on main (bed490b), in the grid, the list and the columns, and 0 with this head merged in, in all three, over two rounds.
  • bin/test passes at this head (197 tests).
  • Merged into main, 210 pass and one fails: chooserWindowAnswersFromTheKeyboard. It fails the same way when main alone is run on the same VM, so it is not caused by this branch.

Second opinion: Codex at medium effort and muse-wonder (via pi, high thinking) reviewed the simplified head and the scroll numbers. They found no defect and agreed that the margins cost only thumbnail preloading, never rows, selection, drag, the rubber band or context menus. Their agreement is not guaranteed to be independent. muse-wonder noticed the test did not need to select anything, because the columns create all three lists up front, so that step is gone. Codex pointed out that the commit message undersold what the margins did, and it now says they also started thumbnails early.

Waiting on:

  • @thisisgm: the description still describes the margins, the old test and the old test count. It should say that the views now only drop the cache buffer, and what that costs while scrolling.
  • The maintainer, once that is updated and CI has finished at this head.

The list and the three lists of the columns each repeated the same
setup: clipping, no dragging, Folio's scroll bar, and now no cache
buffer. FileListView holds it once, with the reason for the buffer, so
the next setting every list needs goes in one place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dhh
dhh merged commit e668b71 into omacom:main Nov 16, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants