Skip to content

perf(clipboard): reconcile cut lists in linear time after moves - #2634

Merged
l0gicgate merged 5 commits into
lgse:mainfrom
GotoFinal:clipboard-perf
Nov 24, 2026
Merged

l0gicgate merged 5 commits into
lgse:mainfrom
GotoFinal:clipboard-perf

Conversation

@GotoFinal

Copy link
Copy Markdown
Contributor

Description

Feel free to do any other implementation as mine might not be good, but needed something working so might as well share here.
Currently large cut+paste operations can freeze whole apps for minutes, like my last cut of 50k files took over 9 minutes...
This is mostly caused by the retain_untransferred method used in the complete_cut_transfer that does some very unoptimized quadratic check due to complexity of locations_equal inside.

This change just basically adds a fancy hashset to bring that time from 460 seconds on my machine to ~ 20ms.

Sadly this is not the only slowdown and second issue will probably require some more discussion as its related to upsert_monitored_entry, during transfer there seems to be some extra logic to apply them in batches, and that works well, but when files are transferred all the new events are processed one by one with each event causing checking of whole folder, so again looking at these 50k files each time, so that still stalled whole app for around 10 extra seconds - the app is unresponsive during that time so can't do anything.

Also its kinda annoying right now as during the move I can't use the same window to do anything else as there is just a big progress modal in my face, why is that?

Visual evidence

N/A, perf only

How to test

  1. Find/make folder with large amount of files, like 5k+ (25 sec on my machine, 9ms after fix)
  2. Ctrl + A, Ctrl + X
  3. Ctrl + V somewhere else

Expected result:

Fast file operations

Finishing a move compared every cut location with every moved location
through locations_equal, which builds and canonicalizes two GFiles per
non-identical pair. ViewState::complete_cut_transfer alone took 5 s for
5,000 files, 26 s for 10,000 and 464 s for 50,000, on the main thread after
the transfer itself had finished.

Match through a LocationSet instead: exact Location lookups first, then one
GFile per location bucketed by URI and confirmed with GFile::equal, so GIO
equivalence (native path vs file:// URI) is unchanged. same_locations, used
when a paste compares the clipboard with the shared cut, uses the same
bucketing for its multiset fallback instead of a nested scan.
complete_cut_transfer now takes 0.02 s for 50,000 files.
JoeJoeflyn and others added 4 commits November 20, 2026 20:41
A copy into an open folder runs as a background operation, which stops
deferring monitor changes, so every copied file was applied on its own:
two scans of the column, a hidden-name pass over every entry and a UI
splice per file. Copying 10,000 files took 45-55 s with the window frozen
for up to 21 s at a time.

Monitor changes still apply one at a time while their columns' sizes
within one burst stay under 100,000 entries. Past that, the rest of the
burst queues in order and publishes every 100 ms through the batch path
that file operations already use, until an interval passes quietly.
Changes applied directly, such as staged load deltas, stay synchronous
unless a batch is pending ahead of them. A starting operation publishes
the queue before it clears it.
Two things differed once a burst of monitor changes went through the batch
path instead of applying one at a time.

A rescan queued behind the burst was stripped by the operation batch path,
which holds rescans until a file operation ends, so the column was never
reloaded. A rescan now publishes the queued burst and reloads its column at
once, as it does outside a burst.

Every batch reported the cursor, as batches deferred by a file operation
do, so each 100 ms flush scrolled the listing back to the cursor and gave
it keyboard focus while files kept arriving. A live batch now reports the
cursor only when it removes the cursor's entry or the column has none,
like a single live change.

Change handling is split into smaller steps so the file's code health does
not drop.
@l0gicgate

l0gicgate commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Review and cleanup

Merged main at 3a95c6790 (no conflicts).

Review against the description. There is no linked issue and there were no review comments or threads to reconcile.

  • Cut lists reconcile in linear time (src/ui/browser/clipboard/matching.rs): confirmed. LocationSet::contains and same_locations give the same answers as the pairwise locations_equal scan, including the multiset behaviour of same_locations; the URI bucketing is sound for GLocalFile and GVfs files, which is everything a cut can hold.
  • Bursts of monitor changes are batched (crates/strata-fs/src/app/browser/live_changes.rs): the design holds up (order is kept, loading columns still record deltas, a starting operation publishes the queue first), but the batch path differed from single changes in two user-visible ways, fixed below.

Fixes pushed in 2010c1f90 fix(browser): make batched monitor bursts behave like single changes

  • A rescan during a burst was lost. Once batching was on, a monitor Rescan was queued, and flush_operation_batch strips rescans into operation_rescan_depths, which is only read when a file operation finishes (and cleared when one starts). The column was never reloaded. The adapter sends a rescan when more than 4,096 changes are pending, when a move and an upsert of its source share a batch, and when a metadata query fails, so this is reachable in exactly the bursts this PR targets. A rescan now publishes the queued burst and reloads the column at once, as on main.
  • Every batch scrolled the listing back to the cursor. publish_operation_batch always emits SelectionSetChanged and FocusChanged, which is right behind an operation's progress dialog but not for live changes: each 100 ms flush scrolled the active column to the cursor and gave it keyboard focus. A live batch now reports the cursor only when it removes the cursor's entry (with triggered_by_removal) or the column has no cursor, which is what a single live change does.
  • receive_directory_change (5 arguments, complexity 11) lowered the CodeScene score of directory_changes.rs from 8.57 to 8.39. It is split into accept_directory_change / apply_or_queue_change, and coalesces_live_change into spend_live_change_budget / queues_live_change; the file now scores 8.79 and operation_updates.rs went from 8.95 to 9.53.
  • docs/architecture.md describes both behaviours.

Tests. None removed: the PR's tests each guard distinct behaviour (GIO-equivalent multiset matching, the 20,000-entry reconcile, burst ordering, an operation starting mid-burst). Added to live_changes/tests.rs:

  • a_rescan_reported_during_a_burst_reloads_the_folder (failed before the fix: the column kept the burst's entries);
  • a_burst_reports_the_cursor_only_when_it_removes_the_cursor_entry (fails without the fix with ["selection", "focus"]).

Manual check (private QA container, scripts/qa-drive.sh, Columns mode, folder of 3,000 files, cursor on the first file, listing scrolled down to rows 160–184, then 400 files created from a shell):

  • before the fix the listing jumped back to file-0000.txt; a 20-file burst, which stays on the single-change path, did not;
  • after the fix the listing stays on rows 160–184, all 400 files are listed, a two-file selection survives, and a burst that deletes the cursor's file moves the cursor to its neighbour.

Validation

  • ./scripts/test-headless.py -- app::browser live_changes clipboard::tests ui::browser::transfer monitor — 635 passed, 0 failed (before the last wording-only edits)
  • ./scripts/test-headless.py -- live_changes clipboard::tests on the final code — 72 passed, 0 failed
  • ./scripts/quality.sh fmt, ./scripts/quality.sh clippy — clean
  • scripts/code-health.sh on the touched files — no file below its main score
  • Not run locally: the full Rust suite and the QA scenarios (no scenario is touched); CI runs the full suite.

Notes for the author and owner

  • The title only covers the clipboard half; the squash commit will also carry the browser batching.
  • A change the browser applies itself while a burst is queued (for example the Move after an in-app rename) now waits up to 100 ms behind the burst. That keeps order and looked fine in review, but it is new.

CI: the fork's run needed approval; approved, and all checks are green on 2010c1f90 (Rust test shards 0–3, quality build and lint, policy checks). The QA scenarios job is dispatch-only and did not run.

@l0gicgate
l0gicgate merged commit 8f397a2 into lgse:main Nov 24, 2026
12 checks passed
l0gicgate added a commit to kettleofketchup/strata that referenced this pull request Nov 24, 2026
The 100 ms flush timer from lgse#2634 stayed attached to the default main
context after its browser was dropped. Its closure is bound to the
thread that created it, so the next test thread that iterated the
context fired it and glib's thread guard aborted the test binary. This
failed Rust tests shard 0 in the local_departures monitor test on
unrelated pull requests.

Refs lgse#2710
l0gicgate added a commit that referenced this pull request Nov 24, 2026
* feat(preview): play animated WebP previews

Animated WebP files showed only their first frame because every WebP went
to the still-image decoder. A local WebP whose header declares an
animation now plays in the media sandbox, like a GIF, when the runtime
FFmpeg has the webp_anim decoder (9.0 or newer, asked once per process).
With an older FFmpeg it keeps the still preview.

FFmpeg's animated WebP demuxer reports no duration and cannot seek, so
-stream_loop stalls and -ss skips to the end. The period comes from the
container's frame durations instead, short animations loop with the loop
filter ahead of the 30 fps conversion within a 256 MiB frame budget, and
offsets are reached by decoding and trimming.

Refs #2710

* fix(preview): keep the animated WebP loop budget from overflowing

The frame budget multiplied the frame count by a canvas size read from an
untrusted header. A 16,384-frame file declaring a 16,777,216 pixel square
canvas wraps to zero bytes, which panics a debug build and passes the
budget in a release build.

Refs #2710

* refactor(preview): clear code-health findings in animated WebP playback

Split the RIFF walk into header and chunk readers, name the software-only,
animation and demuxer-loop conditions, pass the probe request as a struct,
move the WebP routing out of classify, and share one long-animation
assertion between the GIF and WebP playback tests. No behaviour changes.

Refs #2710

* docs(preview): drop comments that restate animated WebP tests

Refs #2710

* fix(browser): remove the live-change flush timer when the browser drops

The 100 ms flush timer from #2634 stayed attached to the default main
context after its browser was dropped. Its closure is bound to the
thread that created it, so the next test thread that iterated the
context fired it and glib's thread guard aborted the test binary. This
failed Rust tests shard 0 in the local_departures monitor test on
unrelated pull requests.

Refs #2710

---------

Co-authored-by: Pierre Berube <[email protected]>
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.

3 participants