Skip to content

Animations: index morph matching and timeline lookups by shape - #1700

Merged
dylanmtaylor merged 2 commits into
mainfrom
fix/sec-anim-index-lookups
Nov 3, 2026
Merged

dylanmtaylor merged 2 commits into
mainfrom
fix/sec-anim-index-lookups

Conversation

@dylanmtaylor

@dylanmtaylor dylanmtaylor commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

What was wrong

Two slideshow paths did work proportional to the product of document-controlled counts, on the rendering thread:

  • morph_pairs searched every shape of the next slide for each unmatched shape of the current slide, in four passes, and rebuilt each shape's text inside every comparison. morph_frame then looked up each pair with linear searches over the pair list and the slide's shapes.
  • Timeline::state_ordered scanned the whole effect list for every shape and paragraph it evaluated, searched the full paragraph-group list for the paragraph's owner, and scanned the colour list for the base colour. paragraph_targets and animated_shapes did similar full scans (with a Vec::contains inside the loop).

A slide with tens of thousands of shapes, or one by-paragraph build over tens of thousands of paragraphs, turned this into billions of comparisons and froze the show.

What changed

  • morph_pairs computes each shape's text once and, per pass, indexes the unused shapes of the next slide by the pass's key (name, kind and text, or kind and preset geometry). The front of each key's queue is the first unused match in slide order, so pairing is exactly what the old search produced.
  • morph_frame builds id lookups for paired shapes once.
  • Timeline builds an index (effects by target shape and paragraph, effects by shape, paragraph owners, groups by shape, base colours) when it is constructed. The fields it indexes are only written during construction. "First wins" semantics of the old find calls are kept.

Blast radius

deckcraft-anim only: morph transitions and animation timeline evaluation. Matching order and results are unchanged; new tests cover slide-order matching and 20,000-shape / 20,000-paragraph cases.

Checks run

  • cargo test -p deckcraft-anim (98 passed, including the new tests)
  • cargo clippy -p deckcraft-anim --all-targets -- -D warnings
  • cargo fmt -p deckcraft-anim --check

Checks not run

  • Full cargo xtask ci and the visual slideshow checks (deckcraft --sample); not run in this environment.

Addresses CodeRabbit security findings (CWE-407).

Summary by CodeRabbit

  • Performance
    • Improved shape morphing and animation timeline processing, especially in presentations with many shapes or paragraphs.
    • Large-slide morph matching and paragraph animation state evaluation now handle more items within tested performance limits.
    • Morph matching continues to respect pass order and slide order when choosing among duplicate matches.

Morph pairing searched every shape of the next slide for each shape of the
current one, four times over, rebuilding shape text inside each comparison.
Timeline state looked up a shape's effects, paragraph owner and base colour
by scanning every effect, group and colour on the slide, once per shape and
paragraph drawn. Both are now indexed once, keeping the same match order.
@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

Morph pairing, frame generation, and timeline evaluation now use keyed indexes and lookups in place of repeated scans. Tests cover duplicate-name ordering and evaluation with 20,000 shapes or paragraphs.

Changes: Animation lookup performance

Layer / File(s) Summary
Morph pairing and frame lookups
crates/anim/src/morph.rs, crates/anim/src/tests.rs
morph_pairs indexes slide shapes by the existing match keys and preserves pass and slide order. morph_frame uses ID lookups for paired shapes and partners. Tests check duplicate-name matching order and pairing and frame generation with 20,000 shapes.
Timeline indexing and state evaluation
crates/anim/src/timeline.rs, crates/anim/src/tests.rs
Timeline builds indexes for effects, paragraph ownership and groups, and base colors. Paragraph-target lookup, animated-shape listing, and state_ordered use indexed or iterator-based lookups. A 20,000-paragraph test checks state before and after the entrance step.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Possibly related issues

  • storytold/deckcraft#1004 — The Morph lookup changes address a source of repeated search work related to the reported slow transitions.
  • storytold/deckcraft#1624 — The Morph lookup changes reduce repeated searches during pairing and frame generation.
  • storytold/deckcraft#1147 — The timeline lookup changes reduce repeated scans during animation state evaluation.

Suggested reviewers: echelon

Merge Risk: Minimal · up to 6b83c

The indexing changes preserve existing animation behavior, and the affected flaky timing assertions have been removed.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main changes: indexing morph matching and timeline lookups by shape.
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 7 functions across 3 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ast-grep (0.51.1)

ast-grep could not parse rule config: /ast-grep-rules/ast-grep-essentials/rules/cpp/security/file-access-before-action-cpp.yml

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between f7fe74c and 6b83c71.

Files selected for processing: 1
  • crates/anim/src/tests.rs

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

@coderabbitai coderabbitai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Fix comments: Fix CodeRabbit comments on this PR

Comment thread crates/anim/src/tests.rs Resolved
… tests

On a loaded runner a ten-second bound can fail after every functional
assertion passed. The inputs stay large enough that a quadratic regression
hangs the test instead.
@dylanmtaylor
dylanmtaylor merged commit 5a668bf into main Nov 3, 2026
9 of 10 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.

1 participant