Skip to content

PERF-EDIT: an edit is followed from what it touched, not worked out from every photo (stacked on #1656) - #1660

Merged
echelon merged 2 commits into
storytold:mainfrom
nledford:view-patch
Oct 15, 2026
Merged

echelon merged 2 commits into
storytold:mainfrom
nledford:view-patch

Conversation

@nledford

@nledford nledford commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #1656 (both change Session::visible): the first commit here is its. The commit "PERF-EDIT: an edit is followed from what it touched, not worked out from every photo" is new.

Problem

Everything derived from the catalog is keyed on its revision, which every op raises. So each edit, however small (a keyword, a rating, every tick of a slider), costs several passes over the whole library:

  • the grid's list is queried and sorted again from every photo;
  • the source is counted by a second full query, sorted only to take its length;
  • the side panels tally the library again: folders, keywords, dates, people, counts.

Keywording through a large library is where it shows: each keyword is followed by a visible pause.

Measured

crates/ui-egui/src/tests_view_cost.rs (ignored; cargo test -p lightcraft-ui-egui --lib what_one_keyword_costs -- --ignored --nocapture): a synthetic library of 67,000 photos, a third of them keyworded from 500 keywords, showing a smart album of the 44,666 without keywords at random. Test profile (optimized), Apple M1 Max, in memory.

The frame after one keyword Before After
Grid, left panel and Keywords panel about 156 ms about 54 ms
Grid and left panel about 138 ms about 40 ms
Grid and Keywords panel about 90 ms about 18 ms
Grid alone about 71 ms about 2 ms

An idle frame is about 2 ms. By stage: the view's list 37 ms → 0.6 ms; the source's count 37 ms → 0; folder tree 13.5 ms, date groups 14 ms and library counts 6.5 ms are no longer tallied after a keyword.

It is a synthetic library: a real one has its own albums, keywords, stacks and a disk under it, so the shape should carry over, not the numbers.

Change

  • The catalog remembers what its latest ops touched (crates/catalog/src/lib.rs): which photos, at which revision, and what of them (Aspects: rating, flag, label, develop, metadata, capture date, file, analysis, presence). Catalog::touched_since(revision) and aspects_since(revision) answer "not known" for an op that changes more than photos of its own (an album, a stack, the keyword list, a label's name…), for changes older than the 8,192 it keeps, and for a revision the catalog did not make itself (a library just loaded takes a range of its own). The kinds of op are listed in a match with no wildcard, so a new kind has to be put on one side.
  • The view follows a small edit (Session::visible, Catalog::follow): the touched photos are taken out of the list it had, asked about again, and put back at their place by binary search on the same ordering the query sorts by (Sort::order). Worked out whole, as before: more than 256 photos touched, a change that is not photos' own, an album shown in its own order, Recently Added, Missing Photos, and a view that asks about "the last N days" (it changes with the clock, not only with edits).
  • The source's count comes from the list when no filter is set; with a filter it is counted without sorting (Catalog::count).
  • The side panels keep a tally an edit cannot have changed (Caches in crates/ui-egui/src/lib.rs): each says what it reads of a photo, and is kept when only other things changed. A rating or a slider changes none of them.
  • ui.inspect → perf reports viewFollowed and viewWorkedOut.

Not in this PR:

  • The count beside each album and smart album in the left panel is still made from every photo on each edit (about 25 ms for one smart album in the library above). It is most of what is left, and grows with the number of smart albums. Keeping each one's members and following them the same way is the next step.
  • The filter bar's lists of cameras, lenses and keywords, and the Keywords panel's own work (about 16 ms above).
  • With a filter set, the source's count is still one pass over the library per edit.
  • Develop should gain as much (every slider tick used to re-tally the library with the left panel open), but that case was not measured.

How it was checked

  • A test that fails without this change
  • User-visible change: nothing looks different; measured instead (above)
  • cargo xtask ci on this branch: run gate by gate, see below

Tests (8 new):

  • crates/engine/src/tests_view_follow.rs, 3: 1,440 random edits (ratings, flags, keywords, titles, sliders, capture dates, files located elsewhere, photos added, removed for good, deleted, made Local, stacked, albums filled and emptied, undo) across six sources, six sorts, three filters, with the hold of LR-LIB-SMARTALBUM: a view can hold its photos until it is refreshed #1656 on for half of them: after each, the followed list equals the list worked out whole, and the session is left as it was, so a list followed many times over is what gets compared; a view that asks about the last 30 days loses its photos when the clock moves on, itself and through a smart album that looks into it; an edit to 500 photos, or to an album, is worked out whole, and nothing changed costs nothing.
  • crates/ui-egui/src/tests_tallies.rs, 2: 600 random edits on a library of files in folders: every tally as the panels would show it equals one made from every photo, also when several edits pass between two looks; a rating or a slider keeps all four, a keyword keeps the folders and dates, a deleted photo or a new album keeps none.
  • crates/catalog/src/tests.rs, 1: the record: photos and aspects per revision, each once; a photo that goes counts for everything; a broad op; a revision set from outside; more ops than are kept; an op that fails; a batch that fails midway, a batch in a batch, a batch with a broad op.
  • tests_view_cost.rs: the measurement (ignored).
  • The nine tests of LR-LIB-SMARTALBUM: a view can hold its photos until it is refreshed #1656 now run through the new path.
  • An existing test caught a real bug on the way: after switching libraries a tally of the old one was kept. Hence "a revision the catalog did not make itself".

Reviewed by a second agent that had not seen the work. Its one blocker, fixed here: a followed view no longer followed the clock for "in the last N days" rules. Also from it: the test's reference list used to reset what it was checking; the random edits now include the kinds that move a photo in each sort; the tally test now uses photos in folders; the counters moved out of library.state. Not covered by a test: the people tally (no test names a face), SetContent under the file-size sort, and the Local browse source.

Rebased onto main after integration batch 35 (2026-10-14), with #1656 under it: no conflict. main's catalog changes (Catalog::repair on opening a damaged snapshot, next_photo with saturating_add, MoveAlbum's bounded cycle check) add no kind of op, so the match that classifies every op needed nothing new; repair runs as a library loads, before any view is followed.

Run on this branch after the rebase: cargo fmt --all --check; cargo clippy -p lightcraft-catalog -p lightcraft-engine -p lightcraft-ui-egui --all-targets -- -D warnings (with -A clippy::chunks_exact_to_as_chunks); cargo xtask parity, layers, assets. The suites were not rerun on this branch itself; they were run on #1662, which contains it (see there).

Run before the rebase: cargo fmt --all --check; cargo clippy -p lightcraft-catalog -p lightcraft-engine -p lightcraft-ui-egui -p lightcraft-mcp --all-targets -- -D warnings (with -A clippy::chunks_exact_to_as_chunks, which rustc 1.99 raises in crates/pipeline on main here); cargo xtask parity, layers, assets, wasm; cargo test for lightcraft-catalog (199 pass), lightcraft-engine (828 pass), lightcraft-mcp (29 pass), lightcraft-ui-egui (807 pass, 6 fail, all in tests_model_setup: "this build cannot run denoise models", the feature being off when this crate is tested alone; untouched here). After those runs only two test files changed (a lint); their tests and clippy were rerun. The whole-workspace run was not repeated.

Merging

Checklist

🤖 Generated with Claude Code

nledford and others added 2 commits October 14, 2026 07:41
A view is asked again after every edit, so a photo that an edit makes stop
matching it leaves the grid at once and every photo after it moves up: a
keyword given in a smart album of photos without keywords takes the photo
away from under the cursor, and in a random order, with no landmarks, the
shift reads as a new shuffle (the seed does not change).

View > Hold View Until Refreshed (`library.holdView`, off by default, kept
with the library's preferences): a photo the view shows stays in it when an
edit makes it stop matching a smart album's rules, Picks or the filter bar.
View > Refresh View (`library.refresh`, also in the sort menu while the hold
is on), Reshuffle, another source, filter or sort, or new rules for the
smart album shown, shows what matches now.

- Photos that start matching still appear at once.
- A photo that is deleted, or taken out of the album or folder shown, still
  leaves at once: a held photo has to be where the view looks
  (`Catalog::query_keeping`, `within`).
- A source with no filter over it holds nothing and is queried as before.
- A refresh keeps the seed.
- The grid's count no longer reads "3 of 2" when a held view shows more than
  now match its source.

Each edit still asks the whole library again; that cost is not addressed
here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rom every photo

Everything derived from the catalog was keyed on its revision, which every
op raises. So each edit (a keyword, a rating, every tick of a slider) had
the grid's list queried and sorted again from every photo, the source
counted by a second full query, and the side panels tally the whole library
again. In a library of 67,000 photos the frame after one keyword took about
156 ms with both side panels open (an idle frame: 2 ms).

The catalog now remembers which photos its latest ops touched and what of
them they changed (`Catalog::touched_since`, `aspects_since`, `Aspects`). It
answers "not known" for an op that changes more than photos of its own (an
album, a stack, the keyword list), for changes too long ago, and for a
revision it did not make itself (a library just loaded).

- The view (`Session::visible`): when the same view is asked again after a
  small edit, the photos the edit touched are taken out of the list it had,
  asked about again, and put back at their place in the order
  (`Catalog::follow`). 37 ms -> 0.6 ms. Worked out whole as before: more
  than 256 photos touched, a change that is not photos' own, an album in its
  own order, Recently Added, Missing Photos, and a view that asks about "the
  last N days" (it changes with the clock too).
- The source's count: taken from the list when no filter is set, else
  counted without sorting (`Catalog::count`). 37 ms -> 0.
- The side panels (`Caches`): the folder tree, keyword tree, date groups,
  people's names and library counts are kept through an edit that changed
  nothing they read. A rating or a slider changes none; a keyword leaves the
  folders, dates and counts.

The frame after a keyword: about 156 ms -> 54 ms with both side panels
open, 71 ms -> 2 ms with the grid alone (`tests_view_cost.rs`, a synthetic
library, run with --ignored --nocapture).

Still paid on each edit: the count beside every album and smart album in the
left panel (about 25 ms for a smart album there), and the filter bar's lists.

Tests: 1,440 random edits of every photo-local kind across sources, sorts,
filters and the hold, each compared with the list worked out whole; 600
random edits comparing every kept tally with a fresh one; the clock; the
record itself, with its failure paths. `ui.inspect` -> `perf` reports
`viewFollowed` and `viewWorkedOut`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nledford added a commit to nledford/lightcraft that referenced this pull request Oct 14, 2026
…tos it touched

The left panel shows a count beside every album. Each catalog revision had
every album counted again, and a smart album's count asks every photo of
the library whether its rules hold: one pass over the library for each smart
album after each keyword, rating or slider tick (about 25 ms an album in a
library of 67,000 photos).

`AlbumTally` (`crates/catalog/src/tally.rs`) keeps the counts and, for each
smart album, which photos it holds. After a small edit each smart album asks
only the photos the edit touched (`Catalog::touched_since`); an album of
chosen photos is counted again only when a photo came, went or was deleted.
Counted from every photo as before: new rules, a change to an album, a stack
or the keyword list, an edit to more than 256 photos, another library, and
each new minute while an album asks about "the last N days".

What an album remembers is in proportion to the photos it holds: a bit a
photo id while ids are close together, a set when they are far apart.

The frame after a keyword in that library, both side panels open: about
54 ms -> 27 ms (156 ms before storytold#1660).

Tests: 900 random edits against eight smart albums (keywords, flags,
ratings, labels, sliders, capture dates, file names, an album of chosen
photos) and an ordinary one, the followed counts compared with
`album_count` after each; a delete followed, three hundred photos counted
whole; the members' bits at the edges and for ids far apart.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@echelon
echelon merged commit 31f1f55 into storytold:main Oct 15, 2026
@echelon

echelon commented Oct 15, 2026

Copy link
Copy Markdown
Member

Thank you @nledford! This landed on main in integration batch 36 (#1843).

If you haven't already, please join our Discord: https://discord.gg/artcraft. We'd love to have you there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants