Repository navigation
Description
Table layout cost rises with the square of the row count. Cost per row rises linearly across a
two-hundred-fold range, so the total rises quadratically, and a table a caller would reasonably build
takes seconds.
Measured
Reproduced here on 486622d (v2.3.2), Release, desktop x64, A4 at 64-point margins, three explicit
120-point columns, one header row plus N body rows of three short cells. Document.Save(string)
only; the probe resolved VellumPdf.Layout at 2.3.2+486622d.
| rows | pages | bytes | save | ms per row |
|---|---|---|---|---|
| 100 | 4 | 5,841 | 38 ms | 0.380 |
| 2,000 | 67 | 89,795 | 338 ms | 0.169 |
| 20,000 | 667 | 891,774 | 7,143 ms | 0.357 |
The 100-row figure carries JIT warm-up, so read the last two: ten times the rows costs twenty-one
times the work. VellumPdfShowcase measured the same shape independently on its own model and
reached 100,000 rows, where cost per row is 1.603 ms and a single save takes 160 seconds.
Why it matters
Seconds, not milliseconds, on input nobody would call abusive. A 20,000-row table is an ordinary
report export. On desktop it is already 7 seconds; a browser tab is far slower again.
It also explains a cap a consumer is carrying. VellumPdfShowcase holds MaxTableRows at 2,000, and
until this measurement that value rested on nothing but a general wish to bound a collection. It now
has a reason, which is a reason to remove rather than to keep.
Where to look
Not diagnosed. The timer excludes construction, so the cost is in layout and serialisation rather
than in building the model. Two candidates worth measuring before changing anything:
- Column resolution, which fix(layout): resolve table columns against every row and the available width #485 changed to resolve against every row. If it runs per continuation
page and rescans every row each time, that alone is quadratic. FindHeaderRowIndicesand the drawn-row bookkeeping inTableRenderer.Draw, which run per page
over row collections.
Attention: measure before fixing. A quadratic shape has more than one candidate here and the
report above establishes the shape, not the cause.
Scope
- Profile a 20,000-row save and name the term that grows.
- A regression test asserting the shape rather than a wall-clock figure: cost per row at two sizes,
with the ratio bounded. A bare timeout would be a wall-clock assertion of the kind Tests: wall-clock assertions flake on the shared CI runner #400 showed to
be unreliable under a loaded CI runner.
Reported by VellumPdfShowcase against published 2.3.2, reproduced here before filing.
Activity
Tim81 commentedon Nov 27, 2026
Causes found in a cost survey on 1dc734d (Release, net10.0), with an experimental patch for each; neither changes output:
TableRenderer.BuildRowspanBlockedSet(:2431-2446, called at :470) rebuilds the row-span set from every row on every page, and itsforeachoverIReadOnlyList<Cell>boxes an enumerator per row. A 16,000-row table on a small page (8,000 pages) allocated 5,082 MB for layout; caching the set per row list brought it to 199 MB._holdsReferences(:122-125) is computed withRows.Any(r => r.Cells.Any(...)), andCarrying(:589-600) does not copy it to the next page's renderer, so every page scans every row and cell again. With fix 1 in place, layout and draw of the same table took 4,810 ms before copying the field and 443 ms after (single runs on a loaded machine).Whole save for that table: 7.2 s before both changes, 0.9 s after (medians of 3; the machine was shared). The tagged variant has a third, separate cost in the save: #728.