Skip to content

PERF-SYNC: a Synchronize Folder scan reads off the folder's listing whether a photo and its sidecar are there - #1602

Merged
echelon merged 1 commit into
storytold:mainfrom
nledford:sync-from-listing
Oct 15, 2026
Merged

echelon merged 1 commit into
storytold:mainfrom
nledford:sync-from-listing

Conversation

@nledford

@nledford nledford commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Its base, #1583, is now in main: after the rebase onto main (integration batch 35, a4b53b28) this pull request is its one commit, 540a281c ("PERF-SYNC: …"). The rebase met only docs/whats-new.md (both entries kept); the code applied unchanged.

Problem

A Synchronize Folder scan of a folder on a network share is slow though nothing in the folder changed. For every photo of the library in the folder it asks the disk whether the file is there and whether it has a sidecar under any of four names (IMG.xmp, IMG.XMP, IMG.jpg.xmp, IMG.jpg.XMP). Each question is a round trip, and the scan has just listed the folder to look for new files: the listing holds every one of those answers.

Change

Engine only (crates/engine/src/walk.rs, sync.rs, import.rs, sidecar.rs).

  • The walk hands over what it lists. walk::files_in_noting calls back with each folder it reads: the name and kind of every entry (hidden ones too) and whether that is all of them (not when the walk stopped inside the folder, or an entry could not be read). files_in is the same walk without the callback and returns what it returned.
  • The scan walks first, then checks. sync::scan_with walks the folder once (import::expand_noting), then checks the library's photos beside the probing of the new files (import::scan_files, the body of import::scan_with after its walk). Before, the checks ran beside the walk.
  • sync::Listing answers where it is sure, and the disk is asked otherwise.
    • A name the folder lists is there, as the kind the listing gives it. A link (or an entry of unknown kind) is not answered.
    • A name is surely not there when the folder was listed to its end, every name in the folder is ASCII, the name asked about is plain ASCII (no ~, no :, no dot or space at its end), and no name in the folder is that name in another case.
    • Never answered: a name Windows takes for a device (aux.jpg, NUL, COM1…), a path that does not end in its file's name, a folder the walk did not list.
  • A sidecar the listing holds is then read for its date as before; one that can't be read is passed over for the next name.

Not in this PR:

  • A folder that holds any name with a character outside ASCII gets the "there" answers only: every name it does not list is still asked about. File systems hold such names equal in more ways than I could list safely (case, where ẞ is SS; how accents are written; marks that are passed over). In such a folder the scan saves less, and its checks now start after the listing, so it can take longer than before by up to the time of the listing.
  • The listing itself is unchanged, and it is the larger half on a hard disk (see the numbers). Listing several folders at once was measured and gained about 12% on the same share; not built.
  • The final pass of Synchronize (re-checking moved and missing files, reading changed sidecars) still asks the disk about each file one at a time. It only touches files that changed.
  • Listing holds every name of the tree until the scan ends (bounded by the walk's limit of 1,000,000 entries).

How it was checked

  • A test that fails without this change
  • cargo xtask ci on this branch: run gate by gate, see below

Numbers. cargo run --release -p lightcraft-engine --example sync_scan_bench -- <folder> (added here: it makes a library of the folder's own files, so nothing has changed, and times the scan; it reads the folder and writes nothing there). An SMB share on a hard disk over a 2.5 Gb LAN, macOS client, folders of JPEGs with ASCII names and no subfolders, each not listed for several minutes before its run:

Folder Listing (cold) Scan after it, before Scan after it, this branch
1,599 photos (warm) 4.6 s under 0.05 s
1,721 photos (warm) 4.7 s under 0.05 s
1,868 photos 4.3 s / 3.7 s 4.8 s under 0.05 s
2,403 photos 5.2 s / 5.0 s 7.1 s under 0.05 s

That is about 3 ms a photo before. "Before" is #1583's commit; before and after were run on different folders of each pair and then swapped, because a second scan of a folder just scanned is answered from the client's cache whichever code runs (both show 0.0 s). The scan's own walk of the folder came right after the benchmark's listing, so it is not in these scan times; in the app it is, and it is unchanged.

On the same share: listing costs about 2 ms an entry and is barely cached between passes (193,000 entries: 521 s, then 455 s; with eight folders listed at once, 389 s).

Tests (3 new):

  • the_listing_answers_only_what_it_is_sure_of: a table of 45 names against a listing: listed, not listed, another case, a link, a folder cut short or not walked, names outside ASCII (among them STRAẞE.jpg asked about as strasse.jpg), Windows' device names and name forms, paths that do not end in a file's name, a name that is no text.
  • a_check_from_the_listing_is_the_check_from_the_disk: a folder on disk with photos that are there or gone and sidecars under every name a sidecar can have; each photo's check with the listing equals its check from the disk, under both namings. The disk is asked 9 times with the listing where it was asked 20 times (the folder holds a name outside ASCII), and not once for a subfolder whose names are all ASCII.
  • a_walk_notes_each_folders_listing: the walk is the same walk noted or not; a folder's listing holds every entry with its kind (a hidden file, a link as neither file nor folder) and says when it is not all of the folder.

Run on this branch (before the rebase): cargo fmt --all --check; cargo clippy --workspace --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; cargo test for lightcraft-catalog, lightcraft-engine, lightcraft-ui-egui, lightcraft, lightcraft-mcp and lightcraft-cli (1,979 tests pass). Not run: cargo xtask wasm, the other crates' tests, and nothing on Windows or Linux.

After the rebase onto a4b53b28: cargo fmt --all --check; clippy -D warnings for lightcraft-engine, all targets (same allowance); cargo xtask parity, layers, assets; cargo test -p lightcraft-engine (855 pass, 6 ignored): all pass. Not rerun after the rebase: the other crates' tests and clippy, cargo xtask wasm, the benchmark.

Reviews. Two independent reviews, and what they changed:

  • The first compared the rule with the disk for about 5,500 generated names on five file systems (APFS with and without case, HFS+, exFAT, FAT32): no difference. It found the two cases named below under Existing edits and libraries, that progress showed nothing during the walk (the count is now set before it), and an assertion that could not fail (fixed).
  • I then narrowed the fall-back for folders with names outside ASCII. The second review broke that on this Mac: a file named STRAẞE.jpg is found as strasse.jpg on APFS, and the narrowed rule said "not there". I took the narrowing out again: the rule is the one the first review tested, with Windows' device names and name forms added.

Merging

Checklist

  • No new panic path in non-test code
  • New code has a caller
  • docs/whats-new.md has its entry. No row of docs/parity-checklist.md describes this
  • Ready to merge

🤖 Generated with Claude Code

…hether a photo and its sidecar are there

The scan asked the disk about every library photo in the folder: is its
file there, and has it a sidecar under any of four names. On a network
share each question is a round trip, and the scan had just listed the
folder. Measured on a hard disk over SMB, for unchanged folders of 1,600
to 2,400 photos: 4.6 to 7.1 s of questions after a listing of 4 to 5 s.

- The walk hands each folder's listing over (`walk::files_in_noting`:
  every entry's name and kind, hidden ones too, and whether that is all of
  them). The scan walks the folder once, then checks the photos beside
  the probing of new files.
- `sync::Listing` answers "is it there" / "is it a file" where that holds
  on any file system: a name the folder lists is there; a plain ASCII name
  is not there when the folder was listed to its end, all its names are
  ASCII and none is that name in another case. Everything else is asked
  of the disk as before (a link, a name Windows reads another way, a
  folder that was not walked, and every name not listed in a folder that
  holds a name outside ASCII).

Now under 0.05 s for those folders. Two things differ on purpose: a file
the folder lists is there though it can't be opened by its path (a folder
that may be listed but not searched, an over-long path), where such
photos were listed as missing; and the answers are the folder as the
walk saw it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nledford nledford changed the title PERF-SYNC: a Synchronize Folder scan reads off the folder's listing whether a photo and its sidecar are there (stacked on #1583) PERF-SYNC: a Synchronize Folder scan reads off the folder's listing whether a photo and its sidecar are there Oct 14, 2026
@echelon
echelon merged commit 4212907 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 40 (#1867), rebased onto main after the previous batches.

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

pehonnet pushed a commit to pehonnet/lightcraft that referenced this pull request Oct 15, 2026
@nledford
nledford deleted the sync-from-listing branch October 15, 2026 10:14
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