Repository navigation
Sheets: a formula whose ranges add up past the budget stops before it reads a cell - #2
Merged
Merged
Conversation
… reads a cell =SUMPRODUCT(A1:T10000, ...) with 16 ranges of 200,000 cells read each range before SUMPRODUCT ran. The budget charged each read, so it ended in #CALC! only at the 16th range, after 3 million cell reads: about 2 s on a laptop, and over 3 s on CI's runners, where the hostile test timed out. A person's sheet with such a formula froze for as long. Now, before a formula is worked out, the engine adds up the cells of every range it is sure to read (all of them, except the parts of IF, IFERROR, IFNA and IFS past the first, which may never be worked out). Each of those reads would be charged its cells anyway, so a total past the budget ends in #CALC! at once, with no cell read. A highlight's test gets the same check. refRange's span moves into refSpan, which both use. Co-authored-by: Pointman <noreply@pointman.ai> Co-authored-by: Claude <noreply@anthropic.com>
This was referenced Nov 15, 2026
Merged
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.
=SUMPRODUCT(A1:T10000, …)with 16 ranges of 200,000 cells read every range before SUMPRODUCT ran. The step budget charged each read, so the formula ended in#CALC!only at the 16th range, after about 3 million cell reads. A sheet holding it froze for that long, and the hostile test "element-wise arrays are capped" timed out at 3 s on CI's runners (https://github.com/spacesheep-dev/skill-sheets/actions/runs/43671424929).What changed
IF,IFERROR,IFNAandIFSafter the first, which may never be worked out.mk), so a total past the budget is#CALC!at once, with no cell read. The result for that cell is the same as before; it just arrives without the work.ruleAt) gets the same check.refRange's span moves intorefSpan, whichsureReadsshares, so both count the same cells.Timing
The four formulas in the hostile test, fastest of 3 runs on an Apple M-series laptop:
SUMPRODUCT((A1:A2000=1)*(A1:GR1=1))SUMPRODUCT((A1:A10000=1)*(A1:ALL1=1))SUM(-(-(…16 deep…A1:T10000)))SUMPRODUCT(A1:T10000, …16 ranges)On CI's runner, the whole "element-wise arrays are capped" test took 2.6 s on main's last green run (https://github.com/spacesheep-dev/skill-sheets/actions/runs/43668981314), and over 3 s for one formula on the two failed runs. With this change it took 0.82 s, 0.37 s and 0.55 s on three runs of this PR's check (https://github.com/spacesheep-dev/skill-sheets/actions/runs/43673088741), all green.
The nested minus is unchanged on purpose. It really makes 15 arrays of 200,000 cells, and the budget stops it after them.
Testing
tests/hostile.js: the 16-range formula is#CALC!and reads no cell but its own. On the old engine it reads 2,800,001 cells and the test fails. A formula within budget reads what it names.IF/IFERROR/IFSwith the big formula in an unused part still give their value. A highlight's test reads nothing.node tests/run.js: 72 passed (Node 22 and 26).npx spacesheep skills lint: well-formed, hashc6e7202d466e.Worth a close look
sureReadsmust never count a range that evaluation might skip. Otherwise a cell that used to work would show#CALC!. The only lazy paths inevaluateare the four inLAZY, and every other call evaluates all of its arguments (n.a.map(ev)).