perf(core): find Takeout sidecars by prefix lookup, not by ranking all

Each photo was ranked against every sidecar in its folder, so a folder
of 10,000 photos took about 30 s to scan. The sidecars are now indexed
by stem and each photo is ranked only against the stems a few range
lookups return: 0.1 s for the same folder, with the same matches (B235).
This commit is contained in:
nvrl committed 2026-10-16 11:41:02 +02:00
1 parent 51800c77d7
commit 60a5a98174
2 files changed
+165 -6

No files matched your search

+24
View File
@@ -100,6 +100,7 @@ a live account since.
| Entry | Title |
|---|---|
| [B235](#b235--scanning-a-large-takeout-folder-takes-half-a-minute) | Scanning a large Takeout folder takes half a minute |
| [B234](#b234--any-folder-can-become-a-sync-root-the-home-folder-included) | Any folder can become a sync root, the home folder included |
| [B233](#b233--signing-out-leaves-the-session-valid-on-proton) | Signing out leaves the session valid on Proton |
| [B232](#b232--names-with--or--show-as-empty-rows-or-are-drawn-as-markup) | Names with & or < show as empty rows or are drawn as markup |
@@ -337,6 +338,29 @@ a live account since.
Newest first.
### B235 — Scanning a large Takeout folder takes half a minute
**Status:** Fixed, not verified live
**Found:** 2026-10-16, architecture audit (`FINDINGS.md` 2.4.1).
**Where:** `SidecarIndex` and `find_sidecar` in `crates/pdfs-core/src/takeout.rs`
**Repro:** Scan a Google Takeout export with 10,000 photos in one folder, as "Photos from 2019"
folders often are.
**Cause.** Each photo was ranked against every sidecar of its folder, so the scan grew with the
square of the folder size: 2,000 photos took 0.8 s, 10,000 took 27–32 s before the import
showed anything.
**Fix.** The sidecars of a folder are kept in a sorted map by stem. Every matching rule needs the
stem to start with a prefix that the photo name determines, so each photo is ranked only against
the stems found by a few range lookups. On the same 10,000 photos the scan takes 0.1 s, with the
same matches: ties still go to the first sidecar by name.
**Test:** `takeout::tests::the_sidecar_index_finds_what_ranking_every_sidecar_finds`, which
compares the index with ranking every sidecar, across every rule.
---
### B234 — Any folder can become a sync root, the home folder included
**Status:** Fixed, not verified live