From 3008b2fd621fd1cc0215c04f5e99cd17a9398efd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kov=C3=A1cs=20B=C3=A1lint=20Hunor?= Date: Sat, 10 Oct 2026 02:54:27 +0300 Subject: [PATCH 1/2] Use a lightweight selection checkbox to speed up item realization Uno's default CheckBox template builds an AnimatedIcon per file item, about a third of the time spent realizing list/grid/details panels. Add a plain border+path template for the item selection checkboxes, a FILES_TRACE UI stall probe, and the ui-slowness investigation notes. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_016FAtbHHLQSiJiYcw2vnKiq --- docs/linux-port/investigations/ui-slowness.md | 90 +++++++++++++++++++ docs/linux-port/performance-tracing.md | 3 + .../Platforms/Desktop/App.Desktop.cs | 1 + .../Desktop/UiResponsivenessProbe.cs | 41 +++++++++ .../Styles/LinuxDesktopResources.xaml | 53 +++++++++++ .../Views/Layouts/DetailsLayoutPage.xaml | 1 + .../Views/Layouts/GridLayoutPage.xaml | 3 + 7 files changed, 192 insertions(+) create mode 100644 docs/linux-port/investigations/ui-slowness.md create mode 100644 src/Files.App/Platforms/Desktop/UiResponsivenessProbe.cs diff --git a/docs/linux-port/investigations/ui-slowness.md b/docs/linux-port/investigations/ui-slowness.md new file mode 100644 index 000000000000..c47fd64b1db2 --- /dev/null +++ b/docs/linux-port/investigations/ui-slowness.md @@ -0,0 +1,90 @@ +# UI slowness investigation (software rendering, headless) + +Question: why does the UI feel slow (~2 s per action reported on Debian 13 KDE), and is it fixable? Everything below was +measured in private Xvfb runs (`scripts/linux/headless-run.sh`, software rendering, `nice -n 19`, Debug build, JIT) on a +16-core desktop CPU with low load. A laptop CPU will be roughly 2-3x slower, which matches the reports. Real KDE +compositor/GPU behaviour is not covered. + +## Method + +- Wall time: `ffmpeg x11grab` at 20 fps on the private display, hashing each frame. For every action (xdotool input, + timestamped by a marker script) the table gives `first` (input to first visual change) and `settle` (input to the last + change before 700 ms of stillness). Resolution is 50 ms. +- UI-thread stalls: `FILES_TRACE=1` now also starts a 10 ms dispatcher timer that logs `[files-ui] stall-ms=N` whenever a + tick arrives more than 50 ms late (`UiResponsivenessProbe`). `max stall` is the longest single block of the UI thread. +- Where the time goes: `dotnet-trace collect --profile dotnet-sampled-thread-time --format Speedscope` around one action, + then inclusive/exclusive time of the UI thread (`Uno_Event_Loop`) from the Speedscope JSON. +- Fixtures: folders with 1,000 and 10,000 empty files of ten extensions, plus a 5-file folder. +- Idle: per-thread CPU ticks over 30 s with no input. + +## Results (ms; before -> after the checkbox change; two runs each, they agreed within ~10%) + +| Action | settle before | settle after | max UI stall before -> after | Top contributors (UI thread) | +| --- | --- | --- | --- | --- | +| Startup to Home painted (Debug/JIT) | ~4700 | n/a | n/a | first paint 2.0 s; JIT, XAML load, Home page | +| Navigate into 1k folder | 1370 | 1020-1120 | 384 -> 223 | item realization/measure (~45%), Skia picture record on UI thread (~30%), StatusBar forced `UpdateLayout` (~15%) | +| Navigate into 10k folder | 675 | 540-585 | 295 -> 239 | same (virtualized, so ~1k cost) | +| Layout details -> grid (1k) | 762 | 460-560 | 273 -> 118 | realizing the new panel's items | +| Layout grid -> list (1k) | 1109 | 1108-1206 | 1142 -> 585 | item realization: 2.4 s CPU -> 1.1 s CPU in the profile | +| Layout list -> cards (1k) | 1116 | 815-864 | 531 -> 370 | item realization | +| Layout cards -> details (1k) | 524 | 273 | 129 -> 153 | item realization | +| Select all, 1k | 1481 | 378-429 | 147 -> 216 | selection events, checkbox state | +| Select all, 10k | 1771 | 1736-1782 | 796 -> 802 | Uno `SelectedItems.Add` per item: `ContainerFromItem` + locked `BulkConcurrentObservableCollection.Count` (O(n^2)) | +| Sort by column click (1k / 10k) | 190-250 | same | 260 | sort + relayout; 10k sort profiles at ~20 ms CPU | +| Context menu: file / folder / empty | 130-190 / 430 / 70 | same | 70-170 | `context-menu-build` 120-230 ms on the UI thread (trace), flyout open ~100 ms | +| Open Settings | 360 | 330 | 230 | window/page creation | +| New tab / close tab | 410-610 / 870-1070 | 460-860 / 740 | 70-170 / 290 | page construction, item realization of the tab shown again | +| Window resize | 90 / 76 | same | up to 130 | relayout | +| Search box typing (8 chars) | n/a | n/a | no stalls | typing path is cheap; results come from a worker | +| Idle (30 s, no input) | 0 ticks on every thread | | | no repaint loop | + +Visual changes at idle: 0 in 5 s. Idle CPU is zero because nothing requests a frame. Caveat found while measuring: simply +subscribing to `CompositionTarget.Rendering` makes Uno render at 60 fps (about 8% CPU idle), so do not add such a probe. + +## Findings + +1. **Rendering backend.** `RenderingBackendSelector` picks Uno's software renderer when no GPU node exists or + `LIBGL_ALWAYS_SOFTWARE`/llvmpipe is set; headless runs report `Software (LIBGL_ALWAYS_SOFTWARE is set)`. Raster + happens on `X11RenderThread`; it was idle in all profiles. Frame invalidation does not cause continuous full-window + repaints: idle is 0 frames and 0 CPU. +2. **The UI thread, not rasterization, is the bottleneck.** Skia raster runs off-thread. What blocks the UI thread is + (a) creating and measuring item containers (Uno `VirtualizingPanelLayout.FillLayout`, templates, bindings) and (b) Uno's + `RecordPictureAndReturnPath` (picture recording and `SKPath.Op` clip math), which runs on the UI thread. Both are CPU + bound and independent of GPU, so software rendering is not the main cause; a GPU would not remove (a) or (b). +3. **Per-item `CheckBox` cost (fixed here).** Every file item has a selection CheckBox. Uno's default CheckBox template + builds an `AnimatedIcon` with a Lottie visual and expression animations per instance, even though the box is invisible + (`Opacity=0`) until hover/selection. In the profile this was about a third of the time to realize a list/grid/details + panel (AnimatedIcon construct + arrange + animation re-evaluation + the GC pressure they cause). Fixed with a plain + border + path template (`Files.SelectionCheckBoxStyle`). +4. **Icons/thumbnails** do not block the UI: icon resolution and file enumeration run on worker threads + (`folder-enumeration-batch` 0.6-1.5 ms per batch of 25 on the worker). `folder-enumeration` for 10k files was 175-400 ms + wall, off the UI thread. +5. **No sync-over-async stalls were seen** in the traced actions. The only blocked-UI pattern was lock contention + overhead in `BulkConcurrentObservableCollection.Count` during select-all of 10k items. + +## Remaining larger ideas (not done) + +- Select-all of 10k items is O(n^2) inside Uno's `ListViewBase` (per-item `SelectedItems.Add`). Needs either a bulk + selection path (suppress per-item container lookups; set selection ranges) or a lock-free `Count`/`IndexOf` snapshot. +- Item templates are still heavy (bindings, `x:Bind` updates, `Files.ListViewItemTemplate` build ~200 ms per screenful). + Candidates: fewer elements per row, `x:Phase`/deferred columns, `x:Load` for rarely visible parts (shield icon, tag + badges, rename popup), reuse via a smaller recycling pool. +- `StatusBar.QueueRemeasure` calls the global `UpdateLayout()` from a property-changed handler (about 165-230 ms once per + navigation, because it forces the item layout early). Measuring only the bar's own panels would avoid the forced + global pass. +- Uno picture recording (`RecordPictureAndReturnPath`, `SKPath.Op`) takes 250-400 ms of UI time per navigation. Fixing it + is upstream (dirty-region/clip handling) or by reducing the number of clipped/animated elements. +- Startup: ~4.7 s to a painted Home page in a Debug JIT build; ReadyToRun/AOT builds and trimming the work done before + the first frame (service construction, settings load) should be measured separately on a release build. +- Context menu build runs on the UI thread (120-230 ms); moving the model building to a worker and only creating + flyout items on the UI thread would cut it roughly in half. + +## Reproducing + +```bash +FILES_TRACE=1 FILES_SANDBOX_SEED= FILES_SANDBOX_DRIVES=scripts/linux/showcase-drives.txt \ + nice -n 19 scripts/linux/headless-run.sh -s 20 -o /tmp/out -a +``` + +where the actions file records the screen (`run `), sends xdotool input and writes +timestamp markers; `[files-ui]` lines in `app.log` give stalls. Only the private Xvfb display is used. diff --git a/docs/linux-port/performance-tracing.md b/docs/linux-port/performance-tracing.md index 795707591d1b..68e40c6a0ad0 100644 --- a/docs/linux-port/performance-tracing.md +++ b/docs/linux-port/performance-tracing.md @@ -37,6 +37,9 @@ message bodies, credentials, or process output are included. | `folder-enumeration` | Batch enumerator lifetime, including consumer time between batches. | | `folder-enumeration-batch` | Directory entries/metadata read on a worker, excluding consumer/UI rendering time. | +With tracing enabled, a 10 ms dispatcher timer also writes `[files-ui] t= stall-ms=` to stderr whenever the UI +thread was blocked for more than 50 ms (see `investigations/ui-slowness.md`). It records timing only. + `completed-or-unwound` means the scope ended, including exception/cancellation paths; it does not claim success. D-Bus records explicitly report `reply`/`fault`. Correlate caller logs to distinguish cancellations/timeouts. diff --git a/src/Files.App/Platforms/Desktop/App.Desktop.cs b/src/Files.App/Platforms/Desktop/App.Desktop.cs index ab0fd8a6d080..17287ef13e46 100644 --- a/src/Files.App/Platforms/Desktop/App.Desktop.cs +++ b/src/Files.App/Platforms/Desktop/App.Desktop.cs @@ -47,6 +47,7 @@ async Task ActivateAsync() MainWindow.Instance.RestorePlacement(Ioc.Default.GetRequiredService()); MainWindow.Instance.Activate(); + UiResponsivenessProbe.Start(UiDispatcher!); MainWindow.Instance.Closed += Window_Closed; MainWindow.Instance.Activated += Window_Activated; diff --git a/src/Files.App/Platforms/Desktop/UiResponsivenessProbe.cs b/src/Files.App/Platforms/Desktop/UiResponsivenessProbe.cs new file mode 100644 index 000000000000..b01b57b79729 --- /dev/null +++ b/src/Files.App/Platforms/Desktop/UiResponsivenessProbe.cs @@ -0,0 +1,41 @@ +// Copyright (c) Files Community +// Licensed under the MIT License. + +using Microsoft.UI.Dispatching; +using System.Diagnostics; + +namespace Files.App +{ + /// + /// Opt-in (FILES_TRACE=1) probe that reports UI-thread dispatcher stalls: a 10 ms timer logs + /// whenever its ticks arrive late. It observes only timing, never content. It deliberately does not + /// subscribe to CompositionTarget.Rendering, which makes Uno render continuously. + /// + internal static class UiResponsivenessProbe + { + private const int TickMs = 10; + private const double StallThresholdMs = 50; + + private static DispatcherQueueTimer? timer; + + public static void Start(DispatcherQueue queue) + { + if (!Files.Platform.Abstractions.Diagnostics.PerformanceTrace.Enabled || timer is not null) + return; + + var last = Stopwatch.GetTimestamp(); + timer = queue.CreateTimer(); + timer.Interval = TimeSpan.FromMilliseconds(TickMs); + timer.IsRepeating = true; + timer.Tick += (_, _) => + { + var now = Stopwatch.GetTimestamp(); + var gap = Stopwatch.GetElapsedTime(last, now).TotalMilliseconds; + last = now; + if (gap > StallThresholdMs) + Console.Error.WriteLine(FormattableString.Invariant($"[files-ui] t={DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()} stall-ms={gap:F0}")); + }; + timer.Start(); + } + } +} diff --git a/src/Files.App/Styles/LinuxDesktopResources.xaml b/src/Files.App/Styles/LinuxDesktopResources.xaml index 6fe72d56c9bd..7c40f516d5cc 100644 --- a/src/Files.App/Styles/LinuxDesktopResources.xaml +++ b/src/Files.App/Styles/LinuxDesktopResources.xaml @@ -135,6 +135,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Files.App/Views/Layouts/DetailsLayoutPage.xaml b/src/Files.App/Views/Layouts/DetailsLayoutPage.xaml index 00946373766f..d18f46215f8f 100644 --- a/src/Files.App/Views/Layouts/DetailsLayoutPage.xaml +++ b/src/Files.App/Views/Layouts/DetailsLayoutPage.xaml @@ -990,6 +990,7 @@ Date: Sat, 10 Oct 2026 08:22:56 +0300 Subject: [PATCH 2/2] Fix Linux checkbox feedback and UI probe logging Co-Authored-By: GPT-6.1-sol (OpenAI Codex) Claude-Session: https://claude.ai/code/session_016FAtbHHLQSiJiYcw2vnKiq --- docs/linux-port/performance-tracing.md | 7 +- .../Desktop/UiResponsivenessProbe.cs | 37 +++++-- .../Styles/LinuxDesktopResources.xaml | 97 +++++++++++++++++-- src/Files.App/Views/Layouts/BaseLayoutPage.cs | 5 + .../Views/Layouts/DetailsLayoutPage.xaml | 2 +- .../Views/Layouts/GridLayoutPage.xaml | 6 +- 6 files changed, 136 insertions(+), 18 deletions(-) diff --git a/docs/linux-port/performance-tracing.md b/docs/linux-port/performance-tracing.md index 68e40c6a0ad0..5f01ed307046 100644 --- a/docs/linux-port/performance-tracing.md +++ b/docs/linux-port/performance-tracing.md @@ -37,8 +37,11 @@ message bodies, credentials, or process output are included. | `folder-enumeration` | Batch enumerator lifetime, including consumer time between batches. | | `folder-enumeration-batch` | Directory entries/metadata read on a worker, excluding consumer/UI rendering time. | -With tracing enabled, a 10 ms dispatcher timer also writes `[files-ui] t= stall-ms=` to stderr whenever the UI -thread was blocked for more than 50 ms (see `investigations/ui-slowness.md`). It records timing only. +With tracing enabled, a 10 ms dispatcher timer queues `[files-ui] t= stall-ms=` whenever tick lateness +(the interval between ticks minus 10 ms) exceeds 50 ms. A worker writes these timing-only records to stderr; +its separate buffer holds at most 128 records and drops new records when full. Tick lateness includes timer scheduling +delays and is not a direct measurement of time spent blocking the UI thread. Disabled startup still calls the probe +and initializes the trace flag, but creates no probe closure, timer, logging worker or buffer. `completed-or-unwound` means the scope ended, including exception/cancellation paths; it does not claim success. D-Bus records explicitly report `reply`/`fault`. Correlate caller logs to distinguish cancellations/timeouts. diff --git a/src/Files.App/Platforms/Desktop/UiResponsivenessProbe.cs b/src/Files.App/Platforms/Desktop/UiResponsivenessProbe.cs index b01b57b79729..47b4a418d88c 100644 --- a/src/Files.App/Platforms/Desktop/UiResponsivenessProbe.cs +++ b/src/Files.App/Platforms/Desktop/UiResponsivenessProbe.cs @@ -3,13 +3,13 @@ using Microsoft.UI.Dispatching; using System.Diagnostics; +using System.Threading.Channels; namespace Files.App { /// - /// Opt-in (FILES_TRACE=1) probe that reports UI-thread dispatcher stalls: a 10 ms timer logs - /// whenever its ticks arrive late. It observes only timing, never content. It deliberately does not - /// subscribe to CompositionTarget.Rendering, which makes Uno render continuously. + /// Opt-in (FILES_TRACE=1) probe that reports dispatcher tick lateness on a background worker. + /// It observes only timing, never content, and avoids CompositionTarget.Rendering, which makes Uno render continuously. /// internal static class UiResponsivenessProbe { @@ -23,6 +23,31 @@ public static void Start(DispatcherQueue queue) if (!Files.Platform.Abstractions.Diagnostics.PerformanceTrace.Enabled || timer is not null) return; + StartEnabled(queue); + } + + private static void StartEnabled(DispatcherQueue queue) + { + var records = Channel.CreateBounded<(long Timestamp, double Lateness)>(new BoundedChannelOptions(128) + { + FullMode = BoundedChannelFullMode.DropWrite, + SingleReader = true, + SingleWriter = true, + AllowSynchronousContinuations = false, + }); + _ = Task.Run(async () => + { + await foreach (var record in records.Reader.ReadAllAsync().ConfigureAwait(false)) + { + try + { + Console.Error.WriteLine(FormattableString.Invariant($"[files-ui] t={record.Timestamp} stall-ms={record.Lateness:F0}")); + } + catch (System.IO.IOException) { } + catch (ObjectDisposedException) { } + } + }); + var last = Stopwatch.GetTimestamp(); timer = queue.CreateTimer(); timer.Interval = TimeSpan.FromMilliseconds(TickMs); @@ -30,10 +55,10 @@ public static void Start(DispatcherQueue queue) timer.Tick += (_, _) => { var now = Stopwatch.GetTimestamp(); - var gap = Stopwatch.GetElapsedTime(last, now).TotalMilliseconds; + var lateness = Stopwatch.GetElapsedTime(last, now).TotalMilliseconds - TickMs; last = now; - if (gap > StallThresholdMs) - Console.Error.WriteLine(FormattableString.Invariant($"[files-ui] t={DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()} stall-ms={gap:F0}")); + if (lateness > StallThresholdMs) + records.Writer.TryWrite((DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), lateness)); }; timer.Start(); } diff --git a/src/Files.App/Styles/LinuxDesktopResources.xaml b/src/Files.App/Styles/LinuxDesktopResources.xaml index 7c40f516d5cc..9ca9e80d1018 100644 --- a/src/Files.App/Styles/LinuxDesktopResources.xaml +++ b/src/Files.App/Styles/LinuxDesktopResources.xaml @@ -164,19 +164,101 @@ StrokeStartLineCap="Round" StrokeThickness="1.5" /> - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -185,6 +267,9 @@ diff --git a/src/Files.App/Views/Layouts/BaseLayoutPage.cs b/src/Files.App/Views/Layouts/BaseLayoutPage.cs index 8696a57b1b90..d06ae3269991 100644 --- a/src/Files.App/Views/Layouts/BaseLayoutPage.cs +++ b/src/Files.App/Views/Layouts/BaseLayoutPage.cs @@ -37,6 +37,11 @@ namespace Files.App.Views.Layouts /// public abstract partial class BaseLayoutPage : Page, IBaseLayoutPage, INotifyPropertyChanged { + public static Style? SelectionCheckBoxStyle => + OperatingSystem.IsLinux() + ? (Style)Application.Current.Resources["Files.SelectionCheckBoxStyle"] + : null; + // Dependency injections protected IFileTagsSettingsService FileTagsSettingsService { get; } = Ioc.Default.GetRequiredService(); diff --git a/src/Files.App/Views/Layouts/DetailsLayoutPage.xaml b/src/Files.App/Views/Layouts/DetailsLayoutPage.xaml index d18f46215f8f..682efac7d645 100644 --- a/src/Files.App/Views/Layouts/DetailsLayoutPage.xaml +++ b/src/Files.App/Views/Layouts/DetailsLayoutPage.xaml @@ -990,7 +990,7 @@