Skip to content

perf(tabs): free closed tabs and stop re-encoding menu icons - #2041

Merged
l0gicgate merged 3 commits into
mainfrom
perf/2021-tab-close-leak
Nov 3, 2026
Merged

l0gicgate merged 3 commits into
mainfrom
perf/2021-tab-close-leak

Conversation

@l0gicgate

Copy link
Copy Markdown
Contributor

Description

Strata slowed down in proportion to uptime (#2021). An overnight soak reproduced it in two hours: every closed tab kept its whole widget tree and ViewState alive, and the registries that every icon creation and preference binding scans (PRIMARY_ICONS, INTERFACE_ICONS, preference listeners, theme listeners, thumbnail viewport hooks) grew by roughly 110 listeners and 160 icons per closed tab, in every view mode. A folder open went from 0.5 s to 2.6 s and an idle main-loop round trip from 1 ms to 9 ms after 300 closes. File watchers were not involved (inotify watches stayed at 10).

The leaks were reference cycles between a tab's widgets and the closures attached to them:

  • the sidebar toggle's step and describe closures captured the toggle itself and the sidebar split (composition/layout.rs), and the sidebar animation tick captured the paned (sidebar_width.rs);
  • device row menus captured the row and the browser view in their option handlers, and volume and password-drive rows captured their own row and the sidebar box (device_menu.rs, sidebar_devices.rs);
  • the footer's reference key controller captures the footer, and more cycles of that shape exist.

Rather than hunt each one, TabWindow::discard and the window unrealize path now call WindowContent::destroy, which disposes the closed tab's widget tree the way gtk_window_destroy disposes a window: dispose drops every widget's signal handlers and controllers, so any cycle through a closure is broken. Widgets a parent keeps for itself (a range's slider) are left to that parent. The specific cycles above are fixed as well, since they also leak on window close. The preview find bar no longer edits a disposed entry during teardown.

Two secondary costs found by the profiler are fixed too:

  • Every column build mirrored its context-menu icons into gio::MenuItem::set_icon with a 96 px texture, which GLib serializes by PNG-encoding it; that dominated a fresh folder open in Columns. The PNG is now encoded once per texture and handed to every item as a gio::BytesIcon.
  • The Back-button history menu (feat(navigation): open the back history from the Back button #1977) built one row per history entry on every List and Icons navigation. The rows are now built when the menu opens, capped at the 50 most recent entries; older entries stay reachable with Back.

The faster column build exposed a race in Columns: a suppressed focus echo (the listing retaking focus) arriving within the 75 ms preview delay cancelled the pending child mirror of a keyboard move, so the automatic preview never opened. schedule_child_mirror now leaves a pending mirror alone when the new focus event cannot schedule one; the mirror re-checks the cursor when it runs.

The tab-close regression test now also requires the closed tab's listing widget to be freed and its preference listeners released.

Visual evidence

N/A: no visible change; the fix is in tab teardown and menu construction.

How to test

  1. Open a folder, press Ctrl+T, wait a moment, press Ctrl+W. Repeat 20 to 40 times.
  2. Open a folder with many entries in Columns mode and note how long it takes; compare with the same action before the repeated tab closes.
  3. In List mode navigate into several folders, then right-click or hold the Back button.

Expected result: folder opens stay as fast after the tab churn as at startup, memory does not grow with each closed tab, and the Back history menu lists the visited folders most recent first and jumps to the chosen one.

Related issue

Closes #2021

Every closed tab kept its widget tree and view state alive through
closures that captured their own widgets, so the icon and preference
registries scanned on each icon creation grew with every close and
folder opens slowed with uptime (#2021). Dispose a closed tab's widget
tree as a window is destroyed, break the sidebar toggle and device row
cycles that also leak on window close, encode each context-menu icon
texture once instead of per column build, and build the Back history
menu when it opens. Keep a pending child mirror when a suppressed focus
echo arrives, which the faster column build exposed.
@l0gicgate
l0gicgate merged commit 978acc8 into main Nov 3, 2026
11 checks passed
@l0gicgate
l0gicgate deleted the perf/2021-tab-close-leak branch November 3, 2026 01:14
l0gicgate added a commit to adamcbrewer/strata that referenced this pull request Nov 3, 2026
Each sort menu build registered a Browser observer, and Browser keeps
observers until its tab closes, so every navigation and view rebuild
added another closure that ran on every browser event for the life of
the tab (the uptime slowdown fixed in lgse#2041). Track mapped menus in a
small registry instead and refresh them from the tab's existing event
dispatch when a sort finishes or a column reloads.

Refs lgse#1652
l0gicgate added a commit that referenced this pull request Nov 3, 2026
* feat(sort): add sorting flyouts and list sort indicators

Add Extension, Created and Unsorted sorting with independent name comparison settings and saved folder/default choices.

Implement design option 3 from #1652, with right-aligned submenu values and List indicators for sorts that visible column headers cannot explain.

Refs #1652

* fix(sort): align submenu rows and move list sort control

Keep submenu titles aligned with the main choices and reduce the visual weight of their selected values. Place the List sort control before Refresh with a gap.

Refs #1652

* fix(sort): align default sort actions with other menu rows

Remove the empty indicator slot from plain sort actions as well as choices and submenu titles.

Refs #1652

* fix(sort): toggle the active menu sort off when selected again

Switch to Unsorted when the checked sort field is selected again, so both primary and flyout choices can be turned off.

Refs #1652

* fix(sort): use apply as default sort wording

Update the action label and its translations in all supported languages.

Refs #1652

* fix(sort): keep menus open while changing sort options

Allow several choices before dismissing the menu with Escape or an outside click. Keep checkmarks, submenu summaries and default actions current while the menu is open.

Refs #1652

* fix(sort): sync open sort menus without a browser observer per pane

Each sort menu build registered a Browser observer, and Browser keeps
observers until its tab closes, so every navigation and view rebuild
added another closure that ran on every browser event for the life of
the tab (the uptime slowdown fixed in #2041). Track mapped menus in a
small registry instead and refresh them from the tab's existing event
dispatch when a sort finishes or a column reloads.

Refs #1652

* test(sort): round-trip a non-default per-folder name comparison

Refs #1652

* fix(sort): keep a finished sort from seeding the next folder at its depth

A sort stays pending after it applies, so once Columns replaced that
column with another folder, the next sort, name-order or default action
there started from the previous folder's request and saved it for the
new folder. Overlay a request only while it is still waiting to apply
to the folder it was made for.

Refs #1652

* fix(sort): treat a missing birth time in full listings as unavailable

Filesystems without birth times (NFS, SFTP) left every listed row's
creation time unknown, so a Created sort refilled the whole folder on
each load, file by file over the network for remote folders, and a
monitored change moved its row ahead of the filled ones.

Refs #1652

* docs(sort): restore the directory metadata note on sort gap targets

Refs #1652

* feat(sort): flatten the sort menu and label its default action Make default

List Extension and Created with the other fields and show Natural,
Alphabetical and Case-sensitive names under a Name order heading, so
no choice hides in a flyout that opens over the listing at the window
edge. Unsorted has no row: unchecking the active field already turns
sorting off. Drop the submenu summaries, their styling and the
submenu-only keyboard routing, and rename the QA scenario to match.

Refs #1652

* fix(sort): match the sort menu's top inset to its bottom

Native context menus open with a padded header row, so their contents only pad the bottom; the sort menu opens on a section title, which sat 8px closer to the top edge than its last row did to the bottom.

Refs #1652

* style(sort): apply rustfmt to the sort menu

* test(icons): wait for the grid layout before checking Left wraps rows

The test pressed Down 100 ms after switching to Icons and assumed the
grid already had several columns. On a loaded CI runner it had not been
laid out yet, so Down reached the second tile and the test failed; this
also failed #2044's own CI. Wait until Down moves a whole row instead.

* test(icons): accept any row start in the Left-wrap test

GTK 4.22, which CI uses, lays the fixture's tiles out about 450 px wide
in a 460 px grid, one per row, where GTK 4.24 fits two. Requiring Down
to pass the second tile therefore always failed on CI. Wait for the
tiles to be laid out, then use whichever row start Down reaches; with
one column Left from the second tile still must not enter the sidebar,
and the test still fails on both versions without #2044's fix.

* test(transfer): keep chooser background stamps from taking the injected check

The chosen-folder check failed or held only the first stamp of the folder, which the chooser's own relocation, relist and freshness work could make first under load, so the check succeeded and the chooser closed. Inject into every unforced stamp of the case and pass over forced freshness stamps.

* test(columns): wait for the autofit animation to end before comparing widths

The animated case read the column after a fixed 280 ms, but its ticks wait for frames, which a loaded runner draws late, so the column was still mid-animation. Wait for the column to end at the saved width instead.

---------

Co-authored-by: Pierre Berube <[email protected]>
wmfeht added a commit to wmfeht/strata-feature-map that referenced this pull request Nov 7, 2026
Sync lgse/strata#2041, #2044, #2045: tab teardown, Icons Left wrap, portal text scaling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: Strata becomes slow after running for a long time (regression of #1402 symptom)

1 participant