You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf(ui-egui): cache PageView body ranges per DocLayout in CanvasState (#8194) - #8222
Caches the Vec<(f64, f64)> page body Y-ranges (bodies) passed to PageView::bodies in CanvasState::page_bodies, keyed by Weak<DocLayout> (Arc::ptr_eq).
Motivation
Part of #8194 (Phase 4 of #8112). canvas::show_pages previously re-allocated and rebuilt the full per-page bodies vector on every frame (including resize, scroll, and ribbon tab switches), even when the underlying DocLayout had not changed.
No actionable comments were generated in the recent review.
Walkthrough
CanvasState now caches page-body vertical bounds for a DocLayout and reuses them while that layout remains alive and pointer-identical. show_pages uses the cached bounds. A test checks reuse for the same layout and cache replacement after a layout change.
CanvasState stores a weak DocLayout reference and shared page-body bounds. It reuses the bounds for the same live layout, rebuilds them for a different layout, and initializes the cache as empty. show_pages uses the cache. The test checks cache reuse and replacement.
Issue 8112 — This PR implements a per-frame canvas allocation and memory work step identified as Phase 4 of the epic.
Suggested reviewers:benandez, vangel76
Merge Risk: Minimal · up to fef57
This change avoids rebuilding page-body ranges on every frame while the document layout is unchanged. No merge-blocking risk was identified.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title "perf(ui-egui): cache PageView body ranges per DocLayout in CanvasState (#8194)" names the main change. The PR adds a cache in CanvasState for the page-body Y-ranges passed to PageView, keye…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title "perf(ui-egui): cache PageView body ranges per DocLayout in CanvasState (#8194)" names the main change. The PR adds a cache in CanvasState for the page-body Y-ranges passed to PageView, keyed by a weak reference to DocLayout and checked by pointer identity. The raw summary confirms this, along with the new cached_page_bodies method and the test. The title is specific and concise, and it follows a conventional commit style. The issue reference #8194 matches the PR description. The title does not mention that the cache is invalidated when the layout changes, but that detail is not needed for a title.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Reviewing files that changed from the base of the PR and between 4daed0b and fef57ec.
Files selected for processing: 2
crates/ui-egui/src/canvas.rs
crates/ui-egui/src/canvas/tests.rs
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Reviewed at fef57ec (static read, all changed files). Caching the PageView body Y-ranges per DocLayout in CanvasState is keyed on the layout Arc, so a relayout gives a fresh entry and nothing stale can be read. Approving.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Caches the
Vec<(f64, f64)>page body Y-ranges (bodies) passed toPageView::bodiesinCanvasState::page_bodies, keyed byWeak<DocLayout>(Arc::ptr_eq).Motivation
Part of #8194 (Phase 4 of #8112).
canvas::show_pagespreviously re-allocated and rebuilt the full per-pagebodiesvector on every frame (including resize, scroll, and ribbon tab switches), even when the underlyingDocLayouthad not changed.Testing
cargo fmt --all -- --checkcargo clippy -p wordcraft-ui-egui --all-targets -- -D warningscargo nextest run -p wordcraft-ui-egui --features craft/ui-testing --lib canvas::tests::cached_page_bodies_reuses_buffer_for_same_layout_and_rebuilds_on_changecargo xtask layersSummary by CodeRabbit