Skip to content

perf(cg): full-viewport frame plan fast path#615

Merged
softmarshmallow merged 1 commit intomainfrom
feature/nostalgic-swirles
Mar 30, 2026
Merged

perf(cg): full-viewport frame plan fast path#615
softmarshmallow merged 1 commit intomainfrom
feature/nostalgic-swirles

Conversation

@softmarshmallow
Copy link
Copy Markdown
Member

@softmarshmallow softmarshmallow commented Mar 30, 2026

Summary

  • Full-viewport fast path: When the viewport fully contains the scene (fit zoom), skip the R-tree traversal and index sort entirely — return 0..n in O(1) instead of O(n log n). Guarded by R-tree size equality check for correctness when layers lack render bounds.
  • sort_unstable: Partial-viewport frames use pdqsort instead of stable merge sort — 2-3x faster for integer data, no stability needed for draw-order indices.
  • Shared image snapshot: Pan and zoom caches share a single image_snapshot() call on non-zoom frames, avoiding a redundant GPU handle allocation.

Measured on 01-135k (135K nodes):

Scenario Metric Before After Delta
rt_pan_slow_fit queue 1,598 µs 485 µs -70%
rt_pan_slow_fit p95 6,317 µs 1,199 µs -81%
rt_pan_slow_zoomed p50 300 µs 151 µs -50%
rt_pan_fast_fit p50 82 µs 41 µs -50%
fl_16ms p50 97 µs 61 µs -37%

Zero test regressions (281 unit + 67 doc/integration). No new clippy warnings.

Test plan

  • cargo test -p cg — all pass
  • cargo check -p cg -p grida-canvas-wasm -p grida-dev — all compile
  • cargo clippy -p cg --no-deps — no new warnings (305, down from 306)
  • GPU benchmark before/after on 135K-node fixture
  • Criterion camera benchmarks — no regressions

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Performance

    • Optimized GPU snapshot caching to reduce redundant allocation during rendering operations.
    • Implemented fast-path visibility detection when the entire scene fits within the viewport, eliminating unnecessary computation overhead for frame planning.
  • Documentation

    • Added documentation describing render optimization strategy and corresponding performance improvements.

… snapshot

When the viewport fully contains the scene (fit zoom), skip the R-tree
traversal and index sort entirely — return 0..n in O(1) instead of
O(n log n). Guarded by R-tree size equality check for layers without
render bounds.

Partial-viewport frames now use sort_unstable (pdqsort) instead of
stable merge sort — 2-3x faster for integer data.

Pan and zoom image caches share a single image_snapshot() call on
non-zoom frames, avoiding a redundant GPU handle allocation.

Measured on 01-135k (135K nodes):
- rt_pan_slow_fit queue: 1598→485 us (-70%)
- rt_pan_slow_fit p95: 6317→1199 us (-81%)
- rt_pan_slow_zoomed p50: 300→151 us (-50%)
- rt_pan_fast_fit p50: 82→41 us (-50%)
- fl_16ms p50: 97→61 us (-37%)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
blog Ready Ready Preview, Comment Mar 30, 2026 9:03am
docs Ready Ready Preview, Comment Mar 30, 2026 9:03am
grida Ready Ready Preview, Comment Mar 30, 2026 9:03am
viewer Ready Ready Preview, Comment Mar 30, 2026 9:03am
3 Skipped Deployments
Project Deployment Actions Updated (UTC)
backgrounds Ignored Ignored Preview Mar 30, 2026 9:03am
code Ignored Ignored Mar 30, 2026 9:03am
legacy Ignored Ignored Mar 30, 2026 9:03am

Request Review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1539d1e8-e594-4858-8a78-2614e2d3c978

📥 Commits

Reviewing files that changed from the base of the PR and between 1a94db1 and 2cfd35e.

📒 Files selected for processing (2)
  • crates/grida-canvas/src/runtime/scene.rs
  • docs/wg/feat-2d/optimization.md

Walkthrough

Optimized GPU snapshot caching and frame visibility selection in the renderer. A single GPU image_snapshot() call now serves both pan and zoom image caches, and a fast-path detection skips R-tree traversal when the camera viewport fully contains the scene. Additionally documented the optimization implementation.

Changes

Cohort / File(s) Summary
Render optimization: GPU snapshot and visibility selection
crates/grida-canvas/src/runtime/scene.rs
Consolidated dual image_snapshot() calls into a single reused snapshot between pan and zoom caches. Added fast-path logic in frame() that skips R-tree traversal and sorting when viewport fully contains scene envelope; otherwise replaced sort() with sort_unstable().
Optimization documentation
docs/wg/feat-2d/optimization.md
Added section describing the full-viewport frame plan fast path optimization and GPU snapshot sharing, including benchmark impact and trigger conditions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

cg, performance

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'perf(cg): full-viewport frame plan fast path' directly and precisely describes the main optimization introduced in the changeset—a performance improvement adding a fast path for full-viewport frame planning in the canvas renderer.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/nostalgic-swirles

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cg Core Graphics performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant