Repository navigation
PERF-IMPORT: a scan, an import and a sidecar write no longer make a table of the whole library first - #1583
Merged
Conversation
…able of the whole library first Setting up Synchronize Folder, an import review or an import made a table of every photo in the library on the session's thread before the first file was looked at, and naming one photo's sidecar worked out who owns every shared sidecar name in the library. In a library of 3.5 million photos (`scan_setup_bench`, release, a folder of 500): 5.8 s before a Synchronize scan, 2.6 s before an import review, 1.7 s before an import, 2.4 s for each sidecar written. - A scan keeps the library as it is (photos are shared, not copied) and looks up the files it finds (`library_files`) and the contents it probes (`library_hashes`) on its own thread. - An import looks the library up with its first files (`ImportJob::look_up_library`), from the library and the options as they were when it was set up. - The owners of shared sidecar names are worked out for the photos asked about (`StemOwners::among`): all five callers name only those photos. - Synchronize Folder names its photos' sidecars in the scan, after it has seen that the folder is there. Now 0.9 s, 0.05 s, 0.05 s and under 1 s. What is found, and how sidecars are named, is unchanged: the tests hold the owners against the table of the whole library as it was made before, and the key made without allocating against the key, for every string of up to six of the characters that decide it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 of 6 tasks
Member
|
Thank you @nledford! This landed on main in integration batch 35 (#1682). If you haven't already, please join our Discord: https://discord.gg/artcraft. We'd love to have you there. |
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.
Problem
In a large library, Synchronize Folder, the import review and an import sit for seconds before they look at the first file, and each XMP sidecar written (Save Metadata to File, or automatically after an edit) takes seconds too. The time does not depend on the folder: it is spent on the whole library, on the session's thread.
The cause is three tables made of every photo in the library:
ScanInput::newbuilt a candidate record and a content-hash entry for every photo (import review, and Synchronize Folder through it).ImportJob::newbuilt a path and a content-hash entry for every photo.StemOwners::ofworked out who owns every shared sidecar name in the library (IMG_1.CR3+IMG_1.JPG→ oneIMG_1.xmp), to name the sidecar of one photo.Change
Engine only (
crates/engine/src/import.rs,sidecar.rs,sync.rs,cmd/xmp.rs).ScanInputkeeps the library as it is (photos areArcs, shared, not copied).scan_withlooks up the files it found (library_files) and, once they are probed, who has their contents (library_hashes): one pass over the library each, on the scan's thread, and a record only for what matched.ImportJobkeeps the library and whether trashed photos are replaced, as they were when it was set up, and makes its two tables with the first files (look_up_library, first thing inprepare_files).StemOwners::among(catalog, ids)works out the owners of the stems of the photos asked about. All five callers (save_sidecar,sidecar_naming,sidecar_namings, the automatic write,xmp.save) only ever name those photos. A plain path's key is written into a reused buffer instead of being allocated (stem_key_into); any other shape of path goes the long way.SyncInputcarries the folder's photo ids; the scan names their sidecars (sidecar::namings_in) after it has seen that the folder is there, and shares one copy of the library with the file scan.Not in this PR:
catalog.querywith a folder filter), which passes over the library on the session's thread. Any pass over the library costs about that much at this size; removing it needs an index of photos by folder in the catalog.ui-egui/src/import.rs), the import's tables are made there with that batch.How it was checked
cargo xtask cion this branch: run gate by gate, see belowNumbers.
N=<photos> cargo run --release -p lightcraft-engine --example scan_setup_bench(added here; a synthetic library of unedited JPEG records, a folder of 500 of them, Apple M1 Max, nothing else running; last of three runs):main(b3d392b4)SyncInput::new)ScanInput::new)ImportJob::new)What moved to the scan's thread: its two look-ups took 826 ms together at 3.5 million photos (
scan_withon a folder that is not on the disk), where the scan took 1,406 ms onmainafter its 2,585 ms of set-up.Tests (8 new, in
import/tests_known.rsandsidecar/tests_stem_owners.rs):mainmakes it (kept as a test-only reference).a B . / \ é(55,987 strings).Run on this branch:
cargo fmt --all --check;cargo clippy --workspace --all-targets -- -D warnings(with-A clippy::chunks_exact_to_as_chunks, which rustc 1.99 raises incrates/pipelineonmainhere);cargo xtask parity,layers,assets;cargo testforlightcraft-catalog,lightcraft-engine,lightcraft-ui-egui,lightcraft,lightcraft-mcpandlightcraft-cli(1,976 tests pass);cargo check -p lightcraft-engine --target wasm32-unknown-unknown. Not run:cargo xtask wasm, and the other crates' tests (they do not depend on what changed).Reviews. Two independent reviews. The first found that the key made without allocating differed from the key for two shapes of path (
..jpg, anda./.), and that the reference in the test was the new code checked against itself; both are fixed (plain_cut, the test-onlyStemOwners::of). The second checked the fixes: 2,015,539 strings of up to eight characters and 111,111 over a wider alphabet, no difference; and reasoned through Windows paths, where it found none either (not run on Windows).Merging
sidecar.rs,sync.rsandcmd/query.rs(who reads a shared stem sidecar). It reads owners; this changes how the owners' table is made. Not checked for textual conflicts.sync.rsorimport.rs: Synchronize Folder: the scan can continue in the background #1124 (in batch Integration batch 34: CI on three platforms, HEIC/AVIF metadata, Dehaze V3, 35 reviewed contributor PRs #1441), Synchronize Folder: a Read row for the new photos, and dialogs remember theirs (stacked on #1095) #1127, LRC-LIB-LIBFOLDERS: catalog queries and streamed file hashing for locating a folder (part 1 of 3) #1122, Import: what the photos themselves carry can be left in the files #1095. Whichever lands second needs a small merge inSyncInput/scan_with; I will do it.unsafe, build scripts, network access, spawned processes, deleted files, CI orxtaskgate changes: none. One new example (scan_setup_bench).Checklist
docs/whats-new.mdhas its entry. No row ofdocs/parity-checklist.mddescribes this (no feature changes);docs/gaps.mdhas no entry for it🤖 Generated with Claude Code