Skip to content

PERF-CATALOG: a smart album's per-photo test stops storing an answer nothing can read - #3121

Merged
aiongg merged 1 commit into
storytold:mainfrom
nledford:perf-answers-memo
Oct 31, 2026
Merged

aiongg merged 1 commit into
storytold:mainfrom
nledford:perf-answers-memo

Conversation

@nledford

@nledford nledford commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Off main.

Problem

Testing one photo against a smart album stored the answer in a per-thread memo (ANSWERS) that is cleared as the same call returns, so nothing could ever read it. Every photo of a smart album's count or view still paid a hash and an insert for that entry.

Change

smart_album_holds (crates/catalog/src/rules.rs) no longer inserts the answer of the outermost question into ANSWERS. Answers worked out by a nested question (a smart album that tests another smart album) are still stored and shared across the outer question, so the protection against repeated work through nested albums stays. EVALUATED is counted before the change, so the tests that count evaluations see the same numbers.

Not in this PR: the memo's other costs, and #2423's cheapest-rule-first ordering. How much of any larger slowdown seen elsewhere this explains is not shown here.

How it was checked

  • cargo xtask ci passes on this branch, rebased on current main: all 8 steps (fmt, clippy, heif, test, parity, layers, assets, wasm) on this Mac. main currently fails clippy at native_menu.rs:492 on macOS (MENU-BAR: clippy passes on macOS again (Quit, About and Settings share one branch) #2973 fixes it); that one-line fix was applied uncommitted for the run and is not in this PR.
  • A test that fails without this change: none, it is a speed change with no behavior change; the existing smart-album and rules tests cover the behavior (cargo test -p lightcraft-catalog filtered to smart_album and rules: 31 passed, 0 failed).
  • User-visible change: ran the app and looked at the result: not a visible change; measured through the CLI instead.

Measured with lightcraft-cli run --library <clone> library.source kind=all album.createSmart … (four creations of a smart album with the rule {"flag":"reject"} per run), release builds of main (c9860ea) and of this branch, a fresh APFS clone of the library per run, backups off, minimum of the 4 creations per run. The library is a generated format-9 catalog of 532,850 library photos (every fifth one rejected), made with a throwaway version of crates/catalog/examples/persist_bench.rs; no real library was used. The Mac was busy with other builds, so the load is recorded:

round main this branch load average at the start of main's run / this branch's
1 90.2 ms 57.1 ms 89.9 / 78.2
2 97.0 ms 81.4 ms 83.0 / 107.0
3 100.9 ms 74.4 ms 112.3 / 140.9

The branch is faster in every round (by 33, 16 and 26 ms), including the two rounds where it ran at the higher load. The size of the gain is noisy at this load; the direction is not.

Review: fresh reviewer at 5875299

Screenshots

None: not a visible change.

Merging

Checklist

  • No new panic path in non-test code
  • New text on screen goes through tr(): no new text
  • The feature's rows in docs/parity-checklist.md and its entry in docs/gaps.md are updated: no feature row changes
  • New code has a caller: no new code, only less work in an existing function
  • Every new image, icon or other asset has its entry in assets/ATTRIBUTION.md: none added
  • Ready to merge

Summary by CodeRabbit

  • Bug Fixes
    • Improved consistency when smart albums are evaluated within other smart albums. Nested evaluations now reuse computed answers, while top-level evaluations continue to clear cached answers after completing. This helps ensure results remain fresh across separate evaluations and avoids unnecessary recomputation during nested evaluation.

The outermost question in smart_album_holds inserted its answer into ANSWERS, and the Forget guard cleared the map as the same call returned, so no question could ever read that entry. Each photo still paid a hash and an insert for it. Only answers worked out by a nested question are kept now; they are shared across the outer question as before.

No behavior change: EVALUATED is counted before the change, nested answers and the depth and cycle limits are untouched.
@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between c9860ea and 5875299.

Files selected for processing: 1
  • crates/catalog/src/rules.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Walkthrough

smart_album_holds now caches computed answers only for nested calls. The outermost call still clears cached answers on exit, but does not cache its own result.

Changes: Smart album answer caching

Layer / File(s) Summary
Nested answer caching
crates/catalog/src/rules.rs
smart_album_holds checks whether a call is outermost and caches its result only when it is nested.

Priority: Low

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Refactor

Suggested reviewers: fredapps, echelon

Merge Risk: Minimal · up to 58752

The cache lifecycle and tally behavior remain correct, with no actionable merge-blocking risk identified.

Pre-merge checks: Passed 4
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly identifies the main performance change: avoiding storage of the outermost smart album answer that cannot be read before cleanup.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@aiongg
aiongg merged commit b18753a into storytold:main Oct 31, 2026
6 checks passed
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