Repository navigation
Grid: per-frame work no longer scales with the whole sheet (#1098) - #1136
Merged
Merged
Conversation
…ed not cloned per cell (storytold#1098) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This was referenced Oct 13, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Part of #1098. Fixes #1053 (nobody had claimed it or opened a PR for it).
What was O(sheet) per frame
paintincrates/ui-egui/src/grid.rsmakes a freshCfCache::new()every frame (so nothing survives from frame to frame). InCfCache::look(crates/engine/src/cf.rs), for every visible cell and every conditional-format rule that covers it:numbers_in) were built on first use, for every rule kind, even ones that read none (expression, cell value, text, blanks, errors, dates). That is a pass over the rule's range clipped to the used range, with adisplay().to_lowercase()string per non-empty cell and a sort. In the issue's workbook the alternate-row rule covers the whole data area (~8,276 x 44 cells), so every frame did that scan, and trimming the range to the data area (as the reporter tried) cannot help;.clone()d for every cell lookup: the sorted number vector and the whole text-count map (fix(cf): each cell lookup clones the full conditional-format statistics cache #1053).So the per-frame cost was O(rule range) once per rule plus O(rule range) per visible cell, instead of O(visible cells).
What changed (engine only,
crates/engine/src/cf.rs)stats_need(rule): statistics are gathered only for rules that read them: numbers/mean/deviation for top-N, above average, colour scales, data bars, icon sets; the text counts for duplicate/unique. Every other rule kind scans nothing. Each rule gathers only the part it reads (previously both parts, always).&RuleStats) instead of cloned per cell.Tests (
cargo test -p gridcraft-engine --lib cf::, 6 pass)needed_statistics_equal_the_full_ones: equality, old vs new: a reference copy of the previous one-pass computation vsRuleStats::buildfor each need, on several ranges (partly empty, text, errors, blank-looking text, outside the used range); numbers and counts compared exactly (floats by bits).rules_that_read_statistics_still_match: duplicate (case-insensitive), top-N and colour scale results throughlook.lookups_do_not_scan_the_range_for_rules_without_statistics: counter (cfg(test)thread-local of cells visited bynumbers_in) on a 10,000-row sheet: 100 lookups with expression, cell-value and no-blanks rules over A1:B10000 visit 0 cells (before: 20,000 per fresh cache); with a top-N rule they visit its 10,000 cells once, not per lookup.Commands run
cargo fmt -p gridcraft-engine,cargo clippy -p gridcraft-engine --all-targets -- -D warnings,cargo test -p gridcraft-engine --lib cf::(plusicon),cargo check -p gridcraft-engine --target wasm32-unknown-unknown,cargo xtask layers. Not run:cargo xtask ci, the ui-egui tests (no ui-egui code changed), a run of the app on a large workbook.NOT fixed (findings, by reading the code; no timings were taken)
DocState::revisiononly counts undoable commands; recalculation andArc::make_mutin place don't change theArcpointer), so it was left out.chartview::paint_objectscallsgridcraft_chart::resolveandrenderfor every chart intersecting the viewport on every frame, with no cache, so a chart with thousands of points is O(points) per frame (relevant to the chart-heavy workbook if charts are in view; not to a chart-free scroll).Geo::new(several times a frame) buildsLineIndexand outlineAxisover all custom row/column sizes, and both scrollbars callSheet::used_range(walks all stored rows). All are O(custom lines / stored rows) per frame; small next to the above, not changed.Unverified
No timing or profile was taken, so this does not claim the issue is resolved. Whether the conditional-format work was the dominant cost in the reporter's workbook is an inference from the code (a whole-area rule re-scanned every frame); a run with their file or a similar synthetic one would confirm it.
🤖 Generated with Claude Code