Skip to content

fix: double-click the fill handle could hang on a sparse neighbour column - #210

Open
Dejan-Port wants to merge 1 commit into
storytold:mainfrom
Dejan-Port:fix-fill-handle-hang
Open

Dejan-Port wants to merge 1 commit into
storytold:mainfrom
Dejan-Port:fix-fill-handle-hang

Conversation

@Dejan-Port

Copy link
Copy Markdown
Contributor

What

Double-clicking the fill handle fills down as far as the neighbouring column has data, by probing one row at a time until it finds an empty cell — capped at 1,000,000 rows so it couldn't literally run forever. But a million one-at-a-time cell lookups is itself long enough to feel like a hang, and the cap only kicks in that late: a single stray value far below the real data in the neighbouring column (not an unusual thing to have in a real spreadsheet someone's been using for a while) makes every double-click of the fill handle probe every empty row in between before it even reaches the value, let alone the cap.

Fix

Lowered the cap to 10,000, which real double-click-fill usage never approaches (if you need to fill further than that you're using a formula or a drag, not a double-click) but which can't itself be felt as a hang.

Testing

cargo test -p gridcraft-ui-egui passes (82 tests across the crate).

🤖 Generated with Claude Code

…lumn

Double-clicking the fill handle fills down as far as the neighbouring
column has data, by probing one row at a time until it finds an empty
cell — capped at 1,000,000 rows so it couldn't literally run forever.
But a million one-at-a-time cell lookups is itself long enough to feel
like a hang, and the cap only kicks in that late: a single stray value
far below the real data in the neighbouring column (not an unusual
thing to have in a real spreadsheet someone's been using for a while)
makes every double-click of the fill handle probe every empty row in
between before it even reaches the value, let alone the cap.

Lowered the cap to 10,000, which real double-click-fill usage never
approaches (if you need to fill further than that you're using a
formula or a drag, not a double-click) but which can't itself be felt
as a hang.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@echelon

echelon commented Oct 11, 2026

Copy link
Copy Markdown
Member

Thanks for looking at this! Review found the stated cause doesn't hold: the fill-down loop already stops at the first empty cell of the neighbour column, so a stray value far down can't extend it — and the 10k cap would truncate genuine fills longer than 10,000 rows. If you have a workbook that reproduces the hang, could you share steps in an issue? Then we can fix the real cause.

If you haven't already, come join us on the ArtCraft Discord: https://discord.gg/artcraft

@FredApps FredApps 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.

Requesting changes.

  1. The premise does not hold, as echelon already noted in the discussion. The loop in the fill-handle handler stops at the first empty cell of the neighbouring column (is_some_and(|v| !v.is_empty())), so a stray value far below the data is never reached and cannot extend the probe. Only a neighbour column that is genuinely filled for a very long stretch makes it run long, and that is exactly the case the cap would now break.

  2. The change is a behaviour regression. Lowering the cap from 1,000,000 to 10,000 silently truncates a legitimate double-click fill when the neighbouring column has more than 10,000 contiguous filled rows, with no message. Excel fills the whole run. Workbooks with tens of thousands of contiguous rows are normal for this app (see the large-workbook work in #208). This removes a deliberate upper bound without a reason that survives scrutiny.

  3. Rule 5: a speed or hang fix needs a measured gain or a reproduction. The PR has neither a workbook or steps that reproduce a hang, nor a before/after timing, and there is no test for the new cap or for a fill over 10,000 rows.

Suggested path: open an issue with a workbook or steps that really hang on double-click fill, and fix that cause (for example, if the cost is per-cell value_ref lookups, scan the neighbour column's stored extent instead of probing row by row). If a cap is still wanted, make it a documented limit with a test, and surface a status message when it truncates.

The branch also conflicts with main now, so it needs a rebase.

Validation for this review was source reading of the whole diff (one file). No hosted checks are reported on head 1330ca0. No local tests were run (PR builds are paused).

aiongg pushed a commit to aiongg/gridcraft that referenced this pull request Oct 22, 2026
…aster

Follow-up to storytold#210, which the reviewer correctly rejected: the stated
cause (a sparse column with a stray distant value) doesn't hold, since
the scan already stops at the first empty cell. This is a different,
narrower fix that doesn't change behaviour for any input — it never
truncates a long fill, unlike storytold#210's cap — only how fast a genuinely
long, densely-populated run is scanned.

grid.rs's fill-handle double-click called Sheet::value_ref once per
row to find where the neighbouring column's data ends. Each call does
a band lookup + row lookup + column lookup (three BTreeMap probes) via
CellStore::get. For a real dense run (e.g. a filled column near the
1,048,576-row sheet limit) that's a lot of point lookups on the UI
thread in one frame: ~59ms for a 1,000,000-row run in a release build
(measured with the new fill_handle_perf example), likely worse under
wasm where GridCraft actually runs in the browser.

- crates/model/src/store.rs: CellStore::contiguous_value_run walks
  each band's row BTreeMap with `range` (one in-order pass per band)
  instead of one `get` per row, so a dense run costs roughly one
  tree-traversal step per row instead of one binary search per row.
  Deliberately narrower than `has`/`get`: a stored cell always decides
  the row on its own (even with an empty value), matching what
  `value_ref`'s callers actually test for, not `has`'s "formula counts
  regardless of its cached value" (used for Ctrl+arrow navigation).
- crates/model/src/sheet.rs: Sheet::last_contiguous_nonempty layers
  `spill` back in wherever contiguous_value_run finds no stored cell,
  exactly where plain `value_ref` would fall through to it.
- crates/ui-egui/src/grid.rs: the fill-handle double-click now calls
  this once instead of looping over value_ref.

Result: 999,999-row dense run, 59.2ms -> 24.7ms (2.40x), same answer
(asserted in the example). Four new tests in sheet.rs, including a
300-trial property test against a naive value_ref-loop reference
(spills, formula-with-empty-value, gaps, blanks) — all pass, plus the
full existing suite (`cargo test -p gridcraft-model -p gridcraft-ui-egui
-p gridcraft-engine`; the only failures are storytold#210-era gridcraft-engine
CSV tests already failing on main, unrelated to this change).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@Harrison-Booth

Copy link
Copy Markdown
Contributor

Hi @Dejan-Port, thanks for this PR. GitHub currently reports a merge conflict between this branch and main (I checked the PR's merge status only; I haven't built or tested it). If it would help, I'm happy to merge the latest main into your branch and resolve the conflicts. Your branch allows maintainer edits, so I'd push a merge commit (no rebase or force-push). Just reply here and say so, or go ahead and update it yourself if you prefer. If we don't hear back, I'll leave it as is for now.

This branch has not been deployed

No deployments
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.

4 participants