Repository navigation
PERF-979: a large library opens in seconds (edited photos are found in the background) - #1277
Merged
Merged
Conversation
…n the background Opening a library spent most of a minute (300,000 photos) in keep_edited_previews_last, which asked every photo's camera defaults, and with them its camera's lookups by name in the profile and camera tables, on the opening thread to find the edited photos whose previews a full cache keeps last. The thumbnail cache's files were never read (attaching it costs 0.2 ms), which is why clearing it changed nothing. - library: the search runs on a thread of its own with a cancellable "Finding edited photos" row, stopped when the library closes; up to 2,000 photos it is done inline (under 10 ms). Each camera is looked up once per pass (Photo::relative_wb_key, camera_defaults_as, looks_as_shot_given): 300,000 photos take about 1 s instead of 60-74 s. - preview: a full cache prunes nothing while the set is pending, and keep_last adds to the set. - the open log splits the stage into thumbnail cache / edited previews / thumbnail cache tidy. - open_bench: realistic raws, an optional thumbnail cache of N KB per photo, background time. 300,000 photos with a 16.5 GB cache: opened in 65.4 / 70.5 s, now 3.8 / 4.0 s. Refs emmertex#979 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
emmertex
approved these changes
Nov 18, 2026
emmertex
left a comment
Owner
There was a problem hiding this comment.
Reviewed: finds edited photos off the opening thread for large libraries (activity-stack row with cancel, cache prunes nothing until the set is known, per-camera lookup memoised), small libraries stay inline. Tests cover large/small/damaged thumbnail cache. Release notes present. CI green.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #979
Problem
Opening a large library takes about a minute. With 300,000 photos and a 16.5 GB thumbnail cache,
library: opened inlogs 65 to 70 s, and nearly all of it is the stage that #1160's log line calls thumbnail cache. For a photographer who keeps years of shoots in one library, that is a minute of waiting at every start.The cache's files are not the cause. Nothing at open reads, lists or counts them (attaching the cache costs 0.2 ms with 300,000 files on disk), which is why clearing the cache left the start as slow as before.
The time goes to
Session::keep_edited_previews_last, which ran inside that stage. To tell which photos are edited (their latest previews are the last a full cache lets go) it calledlooks_as_shoton every photo. That callscamera_defaults()once or twice per photo, and each call runsrelative_wb(), which looks the camera up by name in the.dcpregistry, the spectral table, the Kelvin presets and camdb, normalising strings as it goes. That is about 200 µs per photo, all on the opening thread.Change
library.rs:keep_edited_previews_lasttakes the photos (reference-counted, no copy) and works out the set on a thread of its own, holding a cancellableTaskGuardrow Finding edited photos in the activity stack. It stops when the row is cancelled or the library is closed. A library of up to 2,000 photos (INLINE_EDITED_PHOTOS, under 10 ms) is still done inline, so small libraries show no row. The pass looks each camera up once (relative_wb_key, memoised) instead of once per photo: 300,000 photos take about 1 s in the background instead of 60 to 74 s.disk.rs: while the set is being worked out (keep_last_pending), a full cache prunes nothing, so an edited photo's only rendered picture is never let go before it is known. The first write after the set arrives prunes as before.keep_lastnow adds to the set, so keys added one by one meanwhile stay.Photo::camera_defaults_as(relative)/relative_wb_key(), and crates/engineimport::looks_as_shot_given: the same answers ascamera_defaults/looks_as_shot, given the camera lookup once.thumbnail cache(attach),edited previews,thumbnail cache tidy.examples/open_bench.rs: raws of four bodies with an as-shot white balance, a third of them edited, an optional thumbnail cache of one file of N KB per photo (open_bench <dir> [photos] [thumb KB]), and the time until the background search ends.Not in this PR: reading the catalog (2.5 to 3.9 s here; 1.9 to 3.3 s in the reporter's log) and building the first view (0.8 to 1.4 s). Both grow with the number of photos and are what is left of the open. The second report in #979 (about 20 s on Windows with a smaller library) was not reproduced, so this PR does not claim it.
How it was checked
cargo xtask ci --quickon b3e8846 (Windows, 18 Nov): fmt, brand, quarantine, docs, notes, i18n and clippy pass. In the test step lcc-engine passes 2,518 and lcc-preview passes. Ten tests fail that this change doesn't touch: 1 in lcc-engine (tests_face_recognize::unnamed_faces_come_with_look_alikes…) and 9 in lcc-ui-egui (face and people panels,no_language_has_translation_gapsfor the face labels,translated_catalogs_do_not_use_missing_menu_triangles,ui_text_has_no_em_dasheson a What's New line, bundled-font paint without craft-fonts). All ten failed the same way on another branch from the same base that night. Parity, layers, assets, deny and wasm were run one by one and pass.cargo xtask silwas not run on its own. Main has since merged Raw: decode Nikon NEFX (merged pixel shift) #1267; this branch merges with it without conflicts and was not re-run on it.opening_a_large_library_finds_its_edited_photos_off_the_opening_thread(2,500 raws; the opening thread looks at 0 photos, counted, not timed). Forcing the old inline path makes it look at 2,500.open_benchon a synthetic one (below).Other tests:
opening_a_small_library_finds_its_edited_photos_at_once(20 photos inline, no activity row);a_damaged_thumbnail_cache_opens_and_its_bad_files_go; in lcc-previewa_full_cache_waits_for_the_pictures_to_keep_last,a_cache_whose_keep_last_search_stopped_prunes_againandtruncated_cache_files_are_misses_that_go(empty, marker-only and cut-short files are misses that are removed, never a panic).Before and after: 300,000 photos, 16.5 GB thumbnail cache (300,000 × 55 KB files). Ryzen 9 5950X, 64 GB, NVMe.
open_bench <dir> 300000 55, release build,CHROMAFORGE_PROFILE=1, empty settings folder, warm page cache. The machine was busy with other builds, so absolute times carry noise. Two opens each, in ms:The background times come from a second after-run, where the open itself took 5.3 and 5.6 s because a test build was running alongside. On the first open after the library was made, before: 78.2 s, of which edited previews 73.6 s.
Merging
crates/catalog/src/model.rs,crates/engine/src/import.rsand the locale files too, but not these functions. No open pull request for # Bug (Regression / Follow-up to #934): App Launch Remains Slow and Exceeds 30-Second Initialization Delay Despite Fix #979 found.open_benchexample on a synthetic library.unsafe, build scripts, network access, spawned processes, deleted files, CI orxtaskgate changes: none.Checklist
tr()and has its key in the locale files (one activity row label, 17 languages)🤖 Generated with Claude Code