PerformanceSpreadsheet
How the spreadsheet stays fast with large models, measured times for loading, scrolling, calculation and xlsx files, bundle size, and practical advice for big workbooks.
The spreadsheet is built for models with hundreds of thousands of formulas. Two things keep it fast: the engine only recalculates what changed, and the component only renders what is on screen.
Incremental recalculation#
The engine keeps a dependency graph of every formula:
- Only dirty cells are evaluated. Changing an input marks the formulas that depend on it, directly or indirectly, and only those are evaluated, in dependency order.
- Early cut-off. When a formula's result does not change, the formulas that depend on it are not evaluated again.
- Range indexing. A formula such as
SUM(A1:A100000)is registered once per block of the range rather than once per cell, so large ranges and whole-column references stay cheap to track. - Shared ranges. Formulas that refer to the same range share one entry in the graph, so 20,000 lookups into one table cost one entry, not 20,000.
- Running totals reuse their prefix. Within one calculation pass,
SUM,AVERAGEandCOUNTover a range keep cumulative totals per column block and starting row, soSUM($A$1:A5000)continues fromSUM($A$1:A4999)instead of scanning again. - Criteria functions share an index.
SUMIF(S),COUNTIF(S),AVERAGEIF(S),MAXIFSandMINIFSwith equality criteria over single-column ranges build one table of groups per set of ranges in a pass and answer every formula from it. Criteria with<,>,<>or wildcards scan as before. - Lookups use an index. Exact-match
VLOOKUP,HLOOKUP,MATCH,XLOOKUPandXMATCHbuild a value-to-position index for the looked-up row or column once per pass, and approximate matches use a binary search over it. - Formulas share their parsed form. Formulas that are the same in relative terms, such as a formula filled down a column, share one syntax tree.
- Batching. Changes made together, such as a paste, a fill,
setRange()or abatch()in the headless engine, are recalculated once.
Measured times#
These numbers come from e2e/tests/spreadsheet-perf.spec.ts in the repository, which drives the component in headless Chrome through Playwright. The machine is a desktop with an Intel Core i9-14900K (32 threads). A mid-range laptop will be slower, so measure on the hardware your users have. Where a value moved between runs, the range is given.
Loading and scrolling#
| Scenario | Result |
|---|---|
| Load 1,000,000 rows by 3 columns, including the first paint | 3.1 to 6.1 s across runs, 3.65 s in the last run |
| Wheel scrolling over the 1,000,000 rows | 59.9 frames per second, median frame 16.7 ms, 95th percentile 16.8 ms, no long tasks. The worst single frame was 33 ms in the last run and between 17 and 117 ms across runs. |
| Dragging the scrollbar | 59.7 frames per second, no long tasks |
| Rows in the DOM while scrolling | 28 |
Calculation#
| Scenario | Result |
|---|---|
| Enter 100,000 formulas and calculate them, on the main thread | 287 ms |
| Edit one cell that 50,000 formulas depend on | 17 ms (median) |
| Edit one cell that 100,000 formulas depend on | 29 ms |
| Worker mode: enter 100,000 formulas | 631 ms |
| Worker mode: edit one cell with 100,000 dependants | setValue() returns after 13 ms and the values have settled after 86 ms (77 to 476 ms across runs), with no long task on the main thread |
Excel files#
| Scenario | Result |
|---|---|
| Export 100,000 cells to xlsx on the main thread | 281 ms, a 627 KiB file |
| Import that file on the main thread | 258 ms |
| Export 1,000,000 cells (100,000 rows by 10 columns, one formula per row) in a Web Worker | 1.73 s, a 6.8 MiB compressed file |
| Import that file in a Web Worker | 3.21 s, with no long task on the main thread and a worst main-thread frame of 16.8 ms during the import |
| Export 1,760,000 cells (220,000 rows by 8 columns: four of distinct 60-character text and four of numbers) in a Web Worker | 4.63 s, a 52.6 MB compressed file |
| Import that 52.6 MB file in a Web Worker | 5.67 s, with no long task on the main thread and a worst main-thread frame of 16.8 ms during the import |
The 52.6 MB file is large because its text does not compress; a file of that size made of numbers and repeated text holds several times as many cells and takes longer in proportion to the cells, not the bytes. The importer unzips the file and builds the whole workbook JSON in memory, so memory use grows with the file as well as time: the 52.6 MB import ran in a desktop Chrome worker, and a phone may not have the memory for it.
The worker setup used for the last four rows is the one under Large files in a Web Worker, which also shows how to report progress.
Ranges, criteria and lookups#
Measured in Node 20 with the headless engine, as the median of three runs. "Before" is the same build with the caches described above turned off.
| Workbook | Load before | Load now | Edit before | Edit now |
|---|---|---|---|---|
5,000 running totals, SUM($A$1:A_i) |
285 ms | 36 to 76 ms | 214 ms | 8 to 13 ms |
5,000 exact VLOOKUPs into 5,000 rows |
1,074 ms | 66 to 97 ms | 639 ms | 10 to 18 ms |
20,000 exact VLOOKUPs into 20,000 rows |
32.0 s | 0.28 to 0.42 s | 21.4 s | 38 to 72 ms |
500 SUMIFS over 12,500 rows |
464 ms | 31 to 41 ms | 324 ms | 9 to 13 ms |
2,000 SUMIFS over 50,000 rows |
12.0 s | 0.13 to 0.19 s | 9.3 s | 32 to 36 ms |
"Edit" changes one cell that every formula depends on and reads a result. The ranges in the "now" columns are across runs on a machine that was busy with other work.
Memory#
| Workbook | Heap |
|---|---|
100,000 rows with 200,000 formulas (=A1*2+$A$1 and =SUM(B1,A1) filled down) in the headless engine |
151 MiB, down from 269 MiB; about 680 bytes for a formula cell and 126 bytes for a number |
| A sheet in the component with 5,200,000 numbers | 362 MiB, about 145 bytes for each number |
A sheet of 1,000,000 rows by 200 columns#
A sheet cannot hold 200,000,000 values in a browser tab: at 145 bytes each they would need 29 GB. The test fills the first 20,000 rows of all 200 columns (4,000,000 cells), then column A down to row 1,000,000 and every thousandth row across all 200 columns, 5,200,000 cells in all, so that the used range is 1,000,000 by 200 and scrolling crosses it in both directions.
| Scenario | Full speed | CPU slowed 4 times |
|---|---|---|
| Wheel scrolling down | 60 frames per second, 95th percentile frame 16.8 ms | 19 frames per second, 95th percentile frame 200 ms |
| Wheel scrolling right | 95th percentile frame 16.7 ms | 30 frames per second, 95th percentile frame 100 ms |
| Dragging both scrollbars to the last cell | worst frame 83 to 117 ms | worst frame 100 ms |
| Long tasks over 50 ms during all three | 0 | 168 |
| Edit one cell and repaint | 24 ms | 39 ms |
| Cells in the DOM | 448 | 448 |
Loading the 4,000,000 dense cells with setRange() takes 3.7 to 5.0 s. The "slowed 4 times" column uses Chrome's CPU throttling as a stand-in for a mid-range laptop; it is not a measurement on one. At that speed wheel scrolling over 200 visible columns does not hold 60 frames per second.
Large files: 1, 5 and 10 million cells#
Measured on 29 November 2026 with a synthetic order workbook: ten columns per row, of which five are numbers (two with a number format, one a date), two are text and three are formulas (=D2*E2*(1-F2), =ROUND(G2*0.2,2), =G2+H2), every fifth cell styled. The machine was shared with other work the whole time (1-minute load average 4.8 to 7.4, once 15), so read these as upper bounds; one run of a size, not medians.
Headless, Node 26, createFormulaEngine, jsonToXlsx and xlsxToJSON:
| Cells | Load JSON and calculate | Edit one input | Write xlsx | File | Read xlsx | JS heap of the engine | Process memory at its highest |
|---|---|---|---|---|---|---|---|
| 1,000,000 | 3.1 s | 0.5 ms | 6.7 s | 6.0 MiB | 6.2 s | 402 MiB | 1.5 GiB |
| 5,000,000 | 20.2 s | 0.4 ms | 40.7 s | 30.6 MiB | 44.6 s | 2,170 MiB | 5.5 GiB |
| 10,000,000, as two sheets of 5,000,000 | 35.1 s | 1.3 ms | 86.4 s | 60.0 MiB | 101.7 s | 4,224 MiB | 8.7 GiB |
In Chrome 145, the component with the ribbon, everything on the main thread, opened with openFile() from the xlsx bytes:
| Cells | Open xlsx until calculated and painted | JS heap after opening | Scrolling 90 wheel steps of 6,000 px: median, 95th percentile, worst frame | Edit one input and repaint | Save xlsx |
|---|---|---|---|---|---|
| 1,000,000 | 7.2 s at load 6; 26.3 s at load 15 | 185 MiB | 16.7 ms, 16.8 ms, 33.3 ms | 26 ms | 4.6 to 6.5 s |
| 5,000,000 | 58.0 s | 962 MiB | 16.7 ms, 16.8 ms, 16.8 ms | 23 ms | 41.3 s |
| 10,000,000, as two sheets | The tab crashed before the workbook was open, with Chrome started with a 12 GiB heap limit. The step it crashed in was not determined. |
What limits a large file:
- One sheet holds at most about 8.3 million cells. The workbook JSON keeps the cells of a sheet in one object keyed by address, and V8 refuses more than 2^23 properties on an object ("Too many properties to enumerate"). Ten million cells work only when they are spread over sheets. This is a limit of the data model, not of memory.
- Reading and writing xlsx takes 6 to 10 seconds per million cells and is the slowest step at every size. A profile of the writer is flat: garbage collection 16 %, building rows 10 %, the per-cell patch pass 9 %, then five more passes of 5 to 7 % each, because the file is written in two stages (rows first, then styles, formulas and rich text patched in). Three whole-sheet scans that built a temporary array of every cell were changed to plain loops, worth 6 to 9 % of the write; the two-stage design is unchanged and remains the bottleneck.
- On the main thread the page does not respond while a file of this size opens or saves. Use a Web Worker for the conversion.
- Memory is about 400 to 430 bytes of JS heap per cell in the headless engine for this mix of numbers, text and formulas, and a multiple of that in process memory while a file is being written or read.
- Once open, scrolling and editing do not depend on the size: frames stay at the display rate and an edit that touches three formulas takes a few milliseconds.
Against the limits others publish: Google states 20 million cells or 100 MB for a spreadsheet, and an Excel sheet has 17 billion addresses with a practical limit set by memory. We have opened and saved 5 million cells in the browser and 10 million headless, split over two sheets, at the costs above; 10 million cells crashed the browser tab. We have not opened 20 million cells, a single sheet above 8.3 million cells cannot be represented today, and at 10 million cells the headless engine already needs 4.2 GiB of heap, more than a browser tab allows. On size we are well behind Google Sheets.
Engine tests#
The package's unit tests assert upper limits on the engine alone, in Node: 100,000 formulas recalculate after a shared input changes, a single changed input evaluates exactly one formula, a 100,000-deep dependency chain recalculates without overflowing the stack, a SUM over 100,000 cells updates after one change, 5,000 running totals, 5,000 exact lookups and 2,000 SUMIFS over 50,000 rows recalculate within their limits, and 200,000 formulas stay under 220 MiB of heap. The limits are generous, so a change that makes recalculation an order of magnitude slower fails the build.
Measure your own workbook#
Every recalculation emits recalculated with the number of cells that changed and the time it took:
sheet.on('recalculated', ({ changedCount, ms }) => {
if (ms > 50) console.warn(`Recalculated ${changedCount} cells in ${ms.toFixed(1)} ms`);
});
const full = sheet.recalculate();
console.log(`Full recalculation: ${full.ms.toFixed(1)} ms`);In the headless engine, the event also reports how many formulas were evaluated, and evaluationCount gives the running total, which is useful in performance tests:
const before = engine.evaluationCount;
engine.setCell('Inputs', 'B2', 0.059);
console.log(`${engine.evaluationCount - before} formulas evaluated`);Rendering#
The grid is virtualized in both directions. Whatever the size of the sheet, only the rows and columns in view are rendered, so scrolling a sheet with 100,000 filled rows costs the same as scrolling one with 100. The full address space of 1,048,576 rows by 16,384 columns is available, and empty cells cost nothing: cells are stored sparsely.
Bundle size#
Measured on the built package with Rollup (the bundler behind Vite), minified with esbuild and compressed with gzip -9, excluding @birchui/core, @birchui/license and @birchui/excel:
| What you import | Loaded up front | Loaded on demand |
|---|---|---|
| Everything the package exports | 444 KB | 138 KB |
Only createSpreadsheet |
438 KB | 138 KB |
Only createFormulaEngine |
111 KB | none |
Only xlsxToJSON and jsonToXlsx |
15 KB | 172 KB on the first call |
Only jsonToPdf |
14 KB | 134 KB on the first call |
Only csvToJSON and jsonToCsv |
13 KB | none |
| The stylesheet | 13.3 KB | none |
With esbuild --splitting the createSpreadsheet figure is 441 KB up front and 138 KB on demand. Before the file functions of the main entry became lazy wrappers, esbuild loaded all of it up front. A bundler that inlines dynamic imports into one file gets 574 KB for createSpreadsheet and 580 KB for everything. All figures need the bundler to honour the sideEffects field of the package; with it ignored every import costs the whole 574 KB.
The component loads its xlsx and xls reader and writer, the ods reader and writer, the PDF writer and the password code with a dynamic import() the first time importXlsx, exportXlsx, importOds, exportOds, exportPdf, openFile, saveAs or the File tab needs them. The methods were already asynchronous, so nothing changes for the caller; a bundler that keeps dynamic imports (Vite, Rollup, webpack) puts that code in separate files. A bundler that inlines dynamic imports, such as esbuild without --splitting, produces one file of 527 KB for createSpreadsheet. esbuild with --splitting writes the parts to separate files but its entry file imports all of them up front, so it loads 532 KB as well; only bundlers that drop the unused re-exports of the main entry (Rollup, Vite, webpack) load the parts on demand. The four parts are also separate entry points, @birchui/spreadsheet/xlsx, /pdf, /ods and /encryption, with the same exports as the main entry has for them.
The component is large because it contains the formula engine with its 501 functions, the xlsx readers and writers, the ribbon and dialogs, the chart renderer and the pivot engine. The package tree-shakes, so a script that only calculates, or only converts files, loads the smaller figures above. Load the spreadsheet with a dynamic import() on the pages that need it to keep it out of your main bundle:
const { createSpreadsheet } = await import('@birchui/spreadsheet');Advice for large workbooks#
- Use volatile functions sparingly.
NOW,TODAY,RAND,RANDBETWEEN,RANDARRAY,OFFSETandINDIRECTrecalculate on every change, together with everything that depends on them. PutTODAY()in one cell and refer to it, useINDEXinstead ofOFFSET, and direct references instead ofINDIRECT. - Prefer
SUMIFS,COUNTIFSandXLOOKUPover array formulas that multiply whole ranges, such asSUMPRODUCT((A:A="North")*(B:B)), when the result is a single value. - Spill once instead of copying a formula down. One
=FILTER(...)or=SEQUENCE(...)is a single formula; thousands of copied formulas are thousands of nodes in the graph. - Batch API changes.
setRange()with a 2D array recalculates once; a loop ofsetValue()calls recalculates after each one. - Avoid long chains when a range will do. A running balance that refers to the cell above is fine, but a 100,000-step chain recalculates fully when its first cell changes.
- Move slow recalculation off the main thread. Set
calculation: 'worker'on the component, or run a model of your own withcreateWorkerEngine(), which returns only the values you ask for. - Move imports and exports off the main thread.
xlsxToJSON()andjsonToXlsx()need no DOM and run in a Web Worker; pass the resulting JSON tofromJSON(). UseonProgressto show how far an import is. - Keep iterative calculation off unless the model needs it; with it on, circular groups are recalculated up to
maxIterationstimes.
Pictures#
Measured in Chrome on the development machine by e2e/tests/spreadsheet-images.spec.ts, which asserts looser bounds:
| Case | Result |
|---|---|
| Catalogue with 300 pictures, one per row: import | about 70 ms |
| The same sheet scrolled through all 300 rows | 57 to 60 frames a second, at most 13 picture elements alive at a time |
One 20 MB PNG added through addImage |
shown through a 2048 pixel preview; the page is busy for under 5 ms when it is added |
| The same workbook exported, imported and exported again | about 0.3 to 0.6 s each way, the media part byte for byte the original |
| 150 pictures of about 300 kB scrolled twice and ten sheet switches | at most 80 object URLs alive, none after destroy() |
Base64 encoding and decoding of picture data runs at more than 100 MB a second. Recording an edit for undo does not copy picture data.