Skip to content

JSE-52: linear sheet and relationship lookup, maxSheets limit, abort checks in the workbook phase - #130

Merged
securedeveloper merged 4 commits into
mainfrom
jse-52-linear-sheet-lookup
Dec 1, 2026
Merged

securedeveloper merged 4 commits into
mainfrom
jse-52-linear-sheet-lookup

Conversation

@securedeveloper

Copy link
Copy Markdown
Owner

What

  • Linear lookups. read and readSheetNames looked up each sheet's relationship with a scan over all relationships, and summed sheet sizes with indexOf per sheet: quadratic in the number of <sheet> entries. Relationships are now indexed once; the same for hyperlink relationships per sheet.
  • <col> ranges. Each <col min max> element wrote its properties into every column of its range, so many full-width elements cost 16,384 allocations each. Ranges are now applied in batches from last to first, skipping columns a later range already took; the result is the same (later element wins).
  • New read limit maxSheets (default 10,000, optional member of ReadLimits): the number of sheets xl/workbook.xml may declare. Over it, LimitError (LIMIT_EXCEEDED) while that part is parsed, before any per-sheet work. readSheetNames honours it.
  • Abort signal and yielding in phases that had none: the sheet list (at least every 256 entries), per-sheet bookkeeping including sheets that are missing or not selected, defined names, and stored (uncompressed) parts, which are now tokenized in 256 KB slices.

Why

A workbook declaring very many sheets took minutes to open and blocked the event loop without consulting the abort signal. Measured on 2.1.0 (Node 26): read with one sheet named, 10,000 entries 0.9 s; readSheetNames, 40,000 entries 3.5 s; read, 80,000 entries (a 1 MB file) about 26–59 s in one block.

After: 10,000 entries 57 ms (longest block 15 ms); more are refused by the default limit in under 20 ms; with the limit raised, 140,000 entries read in 0.5 s (longest block 39 ms).

Compatibility

Results, warnings and errors are unchanged for files under the new limit. maxSheets is optional in the public type, so a full 2.1-style ReadLimits object still compiles. Ordinary reads (100k and 1M cells) are within noise of 2.1.0.

Tests

  • Work counters (not time) for 2k, 4k and 8k sheet entries through read (one sheet named, all sheets) and readSheetNames; hyperlinks; <col> ranges, with a randomised comparison against the previous algorithm.
  • maxSheets at and over the limit; it trips before any phase after unzip.
  • The signal is consulted during the sheet list and stops the read.
  • changeset: minor

@securedeveloper
securedeveloper merged commit 7603e7f into main Dec 1, 2026
9 checks passed
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.

1 participant