uttrflow / uttrflow/uttrflow-swift

The clipboard formatting sheet recomputes the diff on every panel update while it is open

Open
#484 0 comments 0 reactions 0 assignees View on GitHub
area:clipboard enhancement P2 performance
Dominant language
Swift
Stars
4
Forks
17
Avg merge
3h 32m
Merged PRs (30d)
277

Description

## What happens

`PanelPresenter` builds the panel's presentation with `sheet: sheet(for: snapshot)` (`Sources/UttrflowUX/PanelPresentation.swift:344`). For a formatting sheet, `sheet(for:)` calls `TextDiff.compare(from: original, to: formatted)` (`Sources/UttrflowUX/PanelSheetPresentation.swift:164-167`) every time. So while the sheet is open, every panel update (a new clip arriving, a selection change, a refresh) recomputes the whole diff. #419 made one diff cheap, and the doc comment on `formattingSheet` (line 183) says "a diff computed once", but it is computed once per presentation, not once per sheet.

## Why it matters

For a large code clip, the diff is the most expensive thing the panel does, and repeating it on unrelated updates makes the panel feel slow exactly when it is showing its most useful sheet.

## How to check

A test in `Tests/UttrflowUXTests` that presents the same snapshot with an open formatting sheet twice shows `TextDiff.compare` running twice (count calls through a seam, or time a large input in a benchmark-style test without wall-clock thresholds, by counting work).

## Acceptance criteria

- The comparison is computed once when the formatting sheet opens (or when its formatted text changes) and reused while it stays open. For example, `PanelSheet.formatting` could carry the computed comparison.
- The sheet's content is unchanged, and the existing `PanelSheetPresentation` tests pass.
- A test shows that a second presentation with the sheet open does not compare again.

Making the diff view itself lazy is a separate, smaller change.

Contributor guide

Open the contributing guide

Research direction

Start in Sources/UttrflowUX/PanelPresentation.swift around line 344 and Sources/UttrflowUX/PanelSheetPresentation.swift around lines 164-167 and 183 to trace how formatting sheets are rebuilt. Read the existing tests in Tests/UttrflowUXTests, then add coverage showing that presenting the same snapshot with an open formatting sheet does not call TextDiff.compare again. Done means the diff is reused while the sheet remains open and the existing sheet content tests still pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
desktop, performance, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.