Skip to content

Feature/improve responsiveness when selecting file browser entries - #128

Merged
markusressel merged 2 commits into
mainfrom
feature/improve-responsiveness-when-selecting-file-browser-entries
Jun 20, 2026
Merged

Feature/improve responsiveness when selecting file browser entries#128
markusressel merged 2 commits into
mainfrom
feature/improve-responsiveness-when-selecting-file-browser-entries

Conversation

@markusressel

Copy link
Copy Markdown
Owner

Asynchronous & Incremental Diff Loading in Snapshot Browser

Description

This pull request resolves the blocking interface lag/freeze that occurs when navigating or changing the selected entry in the file browser.

Previously, selecting a file triggered synchronous filesystem attribute queries (os.Lstat) for every snapshot in the dataset on the main UI thread. In datasets with many snapshots, this caused a significant, blocking delay (input lag) while scrolling.

This PR moves the diff state calculation to a background goroutine, updates the UI incrementally to ensure high responsiveness, and adds proper request cancellation and ordering logic.


Key Changes

1. Asynchronous Diff Computation

  • Modified SnapshotBrowserComponent to compute diff states in a background goroutine rather than synchronously blocking the main UI thread during updateTableEntries.
  • When a new file is selected, the snapshots table is instantly rendered with Unknown (N/A) diff states, giving the user immediate, non-blocking feedback.

2. Presentation Order Synchronization (Top-to-Bottom)

  • Before starting the background calculation, we retrieve the sorted entries in their exact presentation order from the table container (tableContainer.GetEntries()).
  • The background calculation iterates from index 0 to len - 1 of this sorted list, causing the calculated diff states to populate smoothly from top to bottom on the screen (regardless of active sorting parameters, e.g. ascending or descending).

3. Concurrency Safety & Cancellation

  • Introduced diffCancel context.CancelFunc and diffSeq atomic.Uint64 fields to the component.
  • If the user selects a new file or directory before the current calculation finishes, the active background context is canceled immediately to stop filesystem queries, and any stale UI update requests from the previous sequence are discarded.

4. Incremental UI Redraws

  • To prevent rendering bottlenecks from calling SetData() too frequently, the background task updates the table:
    • Immediately after calculating each of the first 5 entries (providing near-instant feedback for the visible rows).
    • In batches of 10 entries for the remainder of the calculation.
    • Once more at the very end to push final changes.

Files Modified

  • internal/ui/snapshot_browser/snapshot_browser.go

Verification

  • Unit tests successfully verified (go test ./...).
  • Build compilation verified (just build).
  • Manually tested scrolling and sorting: navigation is responsive and smooth.

…ancel and diffSeq fields to snapshot_browser.go to track

  cancellation and sequence numbers.
  2. Asynchronous/Incremental Loop: Replaced synchronous table construction with  startAsyncDiffCalculation() . The component now:
      • Instantly renders the snapshots table with  Unknown  ( N/A ) diff states to keep the UI thread completely non-blocking.
      • Spawns a background goroutine to perform  os.Lstat  filesystem diff queries.
      • Dispatches updates to the UI thread using  application.QueueUpdateDraw() .
      • Incremental Redraw: Updates the UI after each of the first 5 calculations (visible entries) for instant visual feedback, and then
      batches updates every 10 calculations to avoid rendering bottlenecks.
      • Strict Cancellation: Immediately aborts and discards older computations when a new directory, file, or dataset is selected.
  3. Verification: Checked all unit tests ( go test ./... ) and compiled the binary successfully ( just build ).
… call snapshotBrowser.tableContainer.GetEntries() on the main thread

  right after updating placeholder states. This gives us the exact order in which entries are sorted on the screen.
  2. Top-to-Bottom Processing: The background calculation goroutine uses this sorted order to iterate and compute diff states sequentially.
  3. Correct Re-sorting: When the UI is incrementally redrawn,  SetData  will correctly re-sort them based on the current active sort
  options, meaning the positions remain synchronized.
@markusressel markusressel added the enhancement New feature or request label Jun 20, 2026
@markusressel
markusressel merged commit 61f226e into main Jun 20, 2026
8 checks passed
@markusressel
markusressel deleted the feature/improve-responsiveness-when-selecting-file-browser-entries branch June 20, 2026 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant