Skip to content

PERF-PRESETS: libraries with thousands of presets stay responsive - #1056

Merged
echelon merged 1 commit into
storytold:mainfrom
OneSlips:pr/preset-performance
Oct 13, 2026
Merged

echelon merged 1 commit into
storytold:mainfrom
OneSlips:pr/preset-performance

Conversation

@OneSlips

Copy link
Copy Markdown
Contributor

Split out of #1012 at a reviewer's request.

Problem

A Lightroom preset collection imported whole (11,113 presets, a 42 MB presets.json) made every interaction take seconds:

  • Session::persist ran after every command and serialized the whole preset list just to compare it with the last write: 609 ms per slider tick (release build, the real collection).
  • The Presets panel deep-cloned every preset into a BTreeMap and built a row, widget id and (with thumbnails) a variant render job for each of them, every frame.
  • The preset pickers (Import dialog, Settings > Import) built a row per preset every frame while open.
  • add_presets and opening a library compared every preset with every other (quadratic).

Fixes

  • Session::presets is now a PresetList whose generation() changes on mutable access. persist serializes only when it (or the profile lists) changed, and skips the write when the bytes hash the same. Opening a library no longer serializes the list once just to remember it.
  • Presets panel: grouping is cached per PresetList::generation() (grouped()), and only rows in view are laid out (rows_in_view() + allocate_space for the rows above/below). Move to Group reads its targets from the cached groups. The panel keeps upstream's current (docking / UI.9) layout.
  • Preset pickers in import.rs and panels/settings.rs use a shared picker_rows() that builds only the rows in view (ScrollArea::show_rows).
  • add_presets and library open use hash indexes instead of pairwise comparisons.

Measured (release, the real 11,113-preset collection)

before after
develop.set 609 ms 2.3 ms
preset.apply 598 ms 3.1 ms
Presets panel rows built per frame (5,000 presets) 5,041 ~20 (2.3 ms)

Tests

  • crates/engine/src/tests_presets_scale.rs: develop commands don't re-serialize unchanged presets (and a change is still saved), generation semantics, a 20,000-preset import. An ignored bench (presets_scale_bench, LIGHTCRAFT_BENCH_PRESETS=<presets.json>) times a real collection.
  • ui-egui headless::tests::presets_panel_with_thousands_of_presets_builds_only_visible_rows guards the virtualization (fails on the old code: 5,041 rows).
  • docs/whats-new.md: one entry, "Large preset collections".

Verification (Windows 11)

  • cargo fmt --all -- --check, cargo xtask parity, layers, assets, wasm: pass.
  • heif step (clippy with --features heif, codecs/heif tests, engine heic test): pass.
  • cargo clippy --workspace --all-targets -- -D warnings: the only errors are the two pre-existing upstream lints (chunks_exact_to_as_chunks in pipeline spots.rs, dead descriptor_copy in catalog lock.rs); clean with -A clippy::chunks_exact_to_as_chunks -A dead_code. Nothing in this PR touches those files.
  • cargo test --workspace --no-fail-fast: the new tests pass (tests_presets_scale::*, headless::tests::presets_panel_with_thousands_of_presets_builds_only_visible_rows). The remaining failures are the known upstream Windows ones, fixed in the separate Windows PR: tests_filesystem_history::* (7), sidecar::tests_repair_* (10), rename::tests::folder_moves_repair_retained_sidecars_before_changing_paths, tests_folders::photos_move_to_another_folder_with_their_sidecars_and_back_on_undo, and editors::tests::desktop_entries_give_their_program. Four timing-sensitive tests failed under the full parallel run and pass alone (apple_photos::tests::shutdown_follows_an_export_into_its_import, export_task::contact_sheet_tests::contact_sheet_menu_dialog_picker_and_background_export, headless::tests::a_screenful_of_small_faces_is_not_evicted_and_left_blank, headless::tests::a_slow_photos_import_never_blocks_the_window).

🤖 Generated with Claude Code

…frame

A Lightroom collection imported whole (11 113 presets, a 42 MB presets.json)
made every interaction take seconds:

- Session::persist ran after every command and serialized the whole preset
  list to compare it with the last write: 609 ms per slider tick (release,
  the real collection). Session::presets is now a PresetList whose generation
  changes on mutable access; persist serializes only when it (or the profile
  lists) changed, and skips the write when the bytes hash the same.
  develop.set: 609 ms -> 2.3 ms; preset.apply: 598 ms -> 3.1 ms.
- The Presets panel deep-cloned every preset into a BTreeMap, built a row,
  widget id and (with thumbnails) a variant render job for each of them every
  frame. Grouping is cached per generation and only rows in view are laid
  out: 5041 -> ~20 rows a frame, 2.3 ms with 5000 presets.
- The preset pickers (Import dialog, Settings > Import) build only the rows
  in view.
- add_presets and opening a library compared every preset with every other
  (quadratic); both use hash indexes now. Opening no longer serializes the
  list once just to remember it.

Tests: develop commands don't re-serialize unchanged presets (and a change
is still saved), generation semantics, a 20 000-preset import, and the
panel building only visible rows (fails on the old code: 5041 rows).
An ignored bench (presets_scale_bench, LIGHTCRAFT_BENCH_PRESETS) times a
real presets.json.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@echelon

echelon commented Oct 13, 2026

Copy link
Copy Markdown
Member

Landed on main in #1438 — thank you, @OneSlips, for the contribution! If you haven't already, come join us on Discord: https://discord.gg/artcraft

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