Skip to content

[Bug]: Each range down to the last row creates a vertex per cell and uses about 300 MB #1893

Open

Description

@jonathanelmgren

Description

A finite range keeps one vertex in the dependency graph for every cell between its corners, empty or not. A range from some row down to the last row of the sheet, such as =SUM(J42:J1048576), therefore creates about a million vertices, even when the column holds only a few values.

Workbooks imported from Excel often contain such ranges, written to cover "everything below the header". A whole-column range (J:J) does not have the cost, but it cannot start below row 1, and J42:J is not supported (#1651).

Steps to reproduce (Node.js, node --expose-gc repro.js):

const { HyperFormula } = require('hyperformula');

const formulas = ['=SUM(B42:B1048576)', '=SUM(C42:C1048576)', '=SUM(D42:D1048576)', '=SUM(E42:E1048576)'];

global.gc();
const before = process.memoryUsage().heapUsed;
const start = Date.now();
HyperFormula.buildFromArray([formulas], { licenseKey: 'gpl-v3', maxRows: 1048576 });
const buildMs = Date.now() - start;
global.gc();
console.log({ heapMB: Math.round((process.memoryUsage().heapUsed - before) / 1048576), buildMs });

Measured on 3.2.0, on an empty sheet apart from the formulas:

Formulas Range Heap used Build time
1 B42:B1048576 311 MB 3.7 s
2 B42:B1048576, C42:C1048576 696 MB 9.1 s
4 B42:B1048576 … E42:E1048576 1,175 MB 16.4 s
4 B:B … E:E 2 MB 0.08 s

Expected: a range that runs to the bottom of the sheet costs about as much as the whole-column range covering it. Actual: about 300 MB and several seconds per range, so a workbook with a few dozen such ranges runs out of memory.

Video or screenshots

None.

Demo

The script above.

HyperFormula version

3.2.0 (the range handling is the same on develop)

Your framework

None (plain TypeScript, in a browser add-in)

Your environment

Node.js 26 on Linux for the measurements; the same failure in Chrome and in Excel's embedded browser.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions