Vanilla-Grid Performance Techniques
The techniques the grid uses to stay responsive at up to a million rows, grouped by area. Each entry describes what the grid does, where the code lives, why it matters, and the measured effect against the implementation it replaced. Where a regression test guards the behaviour, it is named. The figures were taken with the setup under Measurement method. Costs that remain are listed under Known costs.
1. Rendering hot path
1.1 Unchanged rows are not rewritten
Where: features/rendering.feature.js, renderVisibleRows()
Each pool <tr> records the projection entry it shows and the projection version it was rendered against (dataset.vnGridEntryIndex, dataset.vnGridProjectionVersion). A render pass computes rowChanged from those two values (or a forced refresh) and skips every cell write, renderCell included, for a row that already shows the right data. A scroll step therefore writes only the rows that entered the window.
1.2 Pool cells are reused and their events are delegated
Where: features/rendering.feature.js, renderVisibleRows() and _initHeaderDelegatedListeners(); features/interaction-pointer.feature.js, _onBodyCheckboxChange
- Selection checkboxes are created once per pool cell and reused (
cell.firstElementChild). A render pass updates onlycheckedand the row index. A single delegatedchangelistener on the viewport replaces one listener per checkbox, so scrolling creates no DOM nodes and no listener closures. - Header cells carry a
dataset.colIndex. One listener per event type (click,dblclick,pointerdown,dragstart,dragend,contextmenu,mousemove,mouseleave) is registered once per grid on the header, so a header rebuild creates no closures.dragover/dropare handled by the drag-scoped document listeners.destroy()removes the delegated set.
1.3 One layout per scroll frame
Where: features/rendering.feature.js, renderVisibleRows() and _updateSpacerHeights(startIndex, endIndex, metrics)
A render pass reads everything it needs first (scrollTop, viewport height, _getVirtualMetrics()), then only writes: pool rotation, spacer heights, cell content. _updateSpacerHeights() receives the pass's own { vm, domScrollTop } instead of re-reading the DOM, because a read there would land after the rotation had dirtied layout and force a synchronous layout of the whole table in the middle of the pass. The pass's values stay valid after rotation because the viewport sets overflow-anchor: none. Other callers of _updateSpacerHeights() run before any write in their task and still read live. See Row Virtualization § 1.6.
large-dataset-js, 100k rows, 240 frames |
render pass | layouts / frame | style + layout / frame | main-thread task / frame | frames > 20 ms |
|---|---|---|---|---|---|
| custom renderers hidden, before | 4.7–5.3 ms | 1.99 | 6.2–6.8 ms | 15.6–17.5 ms | 5–17 |
| custom renderers hidden, now | 1.26 ms | 1.00 | 3.40 ms | 13.0 ms | 0 |
| sample as shipped, before | 5.63 ms | 1.99 | 8.13 ms | 20.1 ms | 52 |
| sample as shipped, now | 1.37 ms | 1.00 | 4.64 ms | 16.5 ms | 9 |
Grouped, and with search highlighting on, the pass takes 1.2–1.3 ms (was ~5.1 ms). Guard: tests/playwright/scroll-layout-count.spec.js allows at most 1.1 layouts per wheel-driven frame, flat, grouped and scaled.
1.4 Scaled mode renders the whole pool in one pass
Where: features/rendering.feature.js, renderVisibleRows()
Above MAX_VIRTUAL_DOM_HEIGHT (16M px in Blink and WebKit, 4M px in Gecko; ~432k and ~108k rows at the 37 px Fiori row height) the grid runs in scaled mode. Scaled mode fills every pool row, on-screen and buffer, in the same pass, as natural mode does. Deferring the buffer rows to a follow-up scheduler write looked cheaper per pass, but the next pass then read layout the deferred fill had just dirtied, and rewrote most of the same rows. Together with § 1.3 this takes scaled mode from three layouts per frame to one.
| 1M rows (scaled), 240 frames, Chromium | render pass | layouts / frame | style + layout / frame | main-thread task / frame | frames > 20 ms | median frame |
|---|---|---|---|---|---|---|
| before | 9.85 ms | 2.99 | 10.5 ms | 27.4 ms | 145 | 33.3 ms |
| now | 1.60 ms | 1.00 | 5.26 ms | 21.3 ms | 62 | 16.7 ms |
In Firefox (headless, 150k rows, scaled there) the render pass went from 12.2 ms to 2.7–2.8 ms.
1.5 Frozen-column styles are applied once per pool
Where: features/rendering.feature.js, _refreshFrozenStylesForPool(); features/columns-freeze.feature.js, applyFrozenStylesToPoolRows()
Nothing on the render path changes frozen-cell classes or left offsets, so they are applied only when the pool changes or the frozen set changes. initVirtualPool() bumps _poolGeneration; the render pass re-applies frozen styles only when the pool's generation differs from the one they were last applied to; applyFrozenColumnStyles() always applies and records the generation. applyFrozenStylesToPoolRows() touches only the first frozenCount + 1 cells of each row, plus any cells a previous application froze when the count has since shrunk, which also keeps a frozen column's resize drag cheap. See Column Freezing § 7.3.
Measured together with § 1.3 (100k rows, one frozen column plus the selection column, 240 frames): render pass 6.72 → 1.15 ms, frozen-style work per frame 0.93 → 0.003 ms, main-thread task per frame 19.4 → 15.5–16.0 ms, frames over 20 ms 43 → 3–4.
Guard: tests/playwright/frozen-columns-pool.spec.js checks that scrolling applies no frozen styles (a resize settle or pool rebuild landing mid-scroll still applies them by design, and the test allows at most two of those) and that frozen cells keep their classes, offset and stickiness across a scroll, a pool-rebuilding resize, a column reorder, a group toggle and a freeze/unfreeze.
1.6 Horizontal header sync short-circuits
Where: vanilla-grid.js, syncHeaderHorizontalScroll()
_lastSyncedScrollLeft returns early when viewport.scrollLeft has not changed, so vertical scrolling costs one property read (0.015–0.02 ms per call). The header <tr> is cached in _cachedHeaderRowEl by renderHeader(), which also resets the gate so rebuilt cells are always re-synced. The frozen-prefix walk stays live and stops at the first non-frozen cell, because freeze classes can change without a header rebuild.
1.7 Formatters are cached
Where: vanilla-grid.js, _initFormatting()
The default formatInteger creates its Intl.NumberFormat on first use and keeps it in _intlNumberFormat. Construction costs about 0.1 ms and the scroll indicator formats on every update, including every frame of a scrollbar drag. Locale-aware string comparison goes through the shared VanillaGridIntlCache collator cache for the same reason.
1.8 No allocation when walking DOM collections
Where: column, resize and freeze features; vanilla-grid.js
Code that iterates headerColGroup.children or headerRow.children indexes the HTMLCollection directly in a for loop instead of copying it with Array.from(). These loops run during resize drags and scroll, and the copies were discarded immediately.
1.9 DOM is built without HTML parsing
Where: features/rendering.feature.js, renderHeader(), showEmpty(), showError(); templates.js
Header cells are built with createElement and textContent. The empty and error rows are cloned from a cached template in window.VanillaGridTemplates, whose static markup is parsed once per page, and the message is set with textContent. This avoids the HTML parser on every rebuild and means labels and messages are never interpreted as markup.
2. Layout and measurement
2.1 Measure all, then write all
Where: features/columns-resize.feature.js, freezeAllColumnWidths()
When widths must be re-measured, the method clears every <col> width, forces exactly one layout (void headerTable.offsetHeight), reads every header width into an array, and only then writes the widths back. No write is interleaved with the reads, so N columns cost one layout instead of N. The same read/write split is used throughout the grid wherever geometry is read.
2.2 Auto-fit measures a column in three phases
Where: features/columns-resize.feature.js, _measureColumnFitWidth()
Auto-fit measures text with probe <span>s placed in the live cells. Measuring one string at a time (append, read rect, remove) forced a full table layout per cell. The method now:
- appends a probe for every string in the column, reading nothing;
- reads every probe rect, plus every other value the column needs (sort-indicator
offsetWidth, cell widget rects, computed padding and gaps), in one pass; - detaches the probes and computes the width arithmetically.
Batching cannot change the result: the probes are position: absolute and white-space: nowrap, so N live probes measure exactly as one probe reused N times. Probes come from a module-level pool. See Column Resizing.
On northwind-orders-js (25 columns × 51 pool rows) one autoFitAllColumns() went from ~1,476 ms with no frame painted to ~350 ms, with byte-identical widths. § 2.3 brought it lower still.
Guard: tests/playwright/autofit.spec.js pins the probe-independence property; tests/playwright/autofit-performance.spec.js sets a time budget.
2.3 Auto-fit applies all columns in one pass
Where: features/columns-resize.feature.js, autoFitAllColumns()
autoFitAllColumns() sets _autoFitBatch for its loop, so the per-column work that autoFitColumn() does on its own runs once for the whole batch: widths are frozen once before the loop, and applyFrozenColumnStyles() and the tooltip pass (§ 2.5) run once after it. See Column Resizing § 14.2.
| before | now | |
|---|---|---|
autoFitAllColumns(), northwind-orders-js, median of 5 |
236 ms | 128 ms |
… clientWidth / scrollWidth reads |
29,208 / 14,592 | 1,401 / 700 |
| … tooltip, width-freeze and frozen-style passes | 24 / 24 / 24 | 1 / 1 / 1 |
autoFitAllColumns(), large-dataset-js 1M, flat / grouped |
246 / 186 ms | 132 / 110 ms |
Guard: tests/playwright/autofit.spec.js checks that widths are byte-identical to the per-column path (stretch-to-fit on and off, with and without frozen columns) and counts one pass of each per call. autofit-performance.spec.js allows 350 ms.
2.4 Frozen offsets come from <col> widths
Where: features/columns-freeze.feature.js, _computeFrozenLeftOffsets()
Under table-layout: fixed the inline <col> width is authoritative, so frozen-column offsets are computed from headerColGroup.children[i].style.width rather than offsetWidth, which would force a layout if one is pending (for example inside the resize rAF handler). offsetWidth is read only before any width has been frozen.
2.5 Tooltip detection
Where: features/viewport.feature.js, updateTooltips(); features/columns-resize.feature.js
Cells whose text is truncated get a title. Detecting truncation needs geometry reads, so:
- Only visible pool rows are visited, stopping at the first hidden one, not every
<td>in the body. - Reads and writes are batched: every
scrollWidth/clientWidthis read first, then everytitleis written. - Canvas
measureTextcatches what integer geometry misses.scrollWidth > clientWidthis kept as a fast path, but it misses sub-pixel overflow (both values are rounded) and overflow to the left in right-aligned numeric and temporal cells. When it reports no overflow, the text is measured on a lazily created hidden canvas and compared with the cell's content width. Font and padding are read once per column per pass and cached.Range.getBoundingClientRect()is not used because browsers clip it to theoverflow: hiddenbox. - The element that clips is measured, not always the cell. A
renderCellthat puts a widget (avatar, icon) beside the text truncates an inner element carryingvn-grid-truncate-ellipsis, so the cell itself never overflows and the canvas fallback would compare the text with the full cell width, ignoring the widget. When the cell does not carry that class, the pass measures its first descendant that does (falling back to the cell), with its own font/padding cache entry per column; thetitlestill goes on the cell. A custom renderer gets correct tooltips by putting the class on the element that truncates. A tree cell clips in its content span, after the indent, so the span stands in for the cell (avn-grid-truncate-ellipsiselement inside it still wins): the canvas fallback compares the text with the width the indent leaves, and thetitleleaves out a leaf's visually hidden level text, which sits in the cell beside the span (Tree Rows § 9). - The pass is debounced. After scrolling it runs 300 ms after the last render (4–5 ms on a 20-column, 61-row pool). During a column-resize drag the rAF callback calls
scheduleTooltipUpdate()andstopResize()runs one immediate pass when the drag ends: script time per drag frame fell from ~3.6 ms to 0.26–0.58 ms. Auto-fit runs one pass for all columns (§ 2.3).
3. CSS and paint
3.1 Compositing hints only where they are needed
Where: vanilla-grid.css
.vn-grid-virtual-tbodyusescontain: layoutand nowill-change. Pool rows are reused rather than added and removed, sowill-change: contentsdescribed the wrong workload.- The viewport, scrollbar wrapper and scrollbar track carry no layer-promotion hacks (
backface-visibility: hidden,transform: translateZ(0)). - The scrollbar thumbs keep
will-change: transform, because_setThumbTop()/_setHorizontalThumbLeft()write theirtransformon every scroll and drag frame.
3.2 Cell renderers without positioned children
Where: samples/large-dataset-js/app.js, the rating and height renderers
Positioned and transformed elements inside a cell are painted as separate layers, multiplied by every visible row. The sample's star rating is a single element filled by a hard-stop linear-gradient clipped to the glyphs (background-clip: text). The height gauge is a single element with four background layers (value marker, ticks, band, track). The value-dependent parts are custom properties. Compared with the earlier positioned markup (100k rows, 120 traced frames): Paint events per frame 93.8 → 2, main-thread task per frame 16.7 → 15.1–15.5 ms. Row Virtualization § 1.16 gives the same advice for host renderers.
4. Data and selection
4.1 The selection key map is built lazily
Where: features/selection.feature.js; vanilla-grid.js, setRows() and appendRows()
The key → row Map has one lookup consumer, setSelectedKeys(), so it is built only there, on first use after a load, together with duplicate-key detection:
setRows()drops the map (invalidateKeyToRowMap()) instead of rebuilding it over every row.appendRows()extends it with the new page only (addRowsToKeyMap()), and only while one exists.setColumns()drops it only when the row-key column actually moves.- A load refreshes the selected rows' snapshots in one pass (
syncSelectionToRows()) and resolves no key at all while nothing is selected. - A
'noselection'grid never builds a map.
Duplicate-key warnings therefore appear at the first setSelectedKeys() after a load. See Selection § 4.
1M rows, large-dataset-js flat |
longest task, before | now |
|---|---|---|
reload() |
301 ms (key map 247 ms) | 57 ms |
| clear the search | 718–742 ms | 60 ms |
| clear a column filter | 615–856 ms | 61 ms |
| search "ali" | 121 ms | 52 ms |
| filter Salary > 150,000 | 139 ms | 52 ms |
| grouped, clear the search | 649 + 304 ms | one task of 317 ms |
The map also held ~33 MB at a million rows.
4.2 Select-all is a predicate
Where: features/selection.feature.js
Select-all is held as a scope flag plus a set of rows unticked since, meaning "every row matching the query, except these". No key is enumerated, so the cost of the header checkbox does not depend on the row count, and syncSelectionToRows() returns immediately while it is active. See Selection § 2 and § 9.
| 1M rows, flat | before | now |
|---|---|---|
header checkbox click (selectAll()) |
610–640 ms | 13–19 ms, ~12 ms of it the viewport re-render |
_selectedKeys + _selectedRowsCache afterwards |
~33 MB | empty |
reload() with every row selected |
355 ms longest task | no long task; 59 ms in all |
Guard: tests/playwright/selection-select-all-performance.spec.js (no key enumerated, under 50 ms).
4.3 The toolbar reads the selection count, not the selection
Where: src/vanilla-grid-toolbar/vanilla-grid-toolbar.js, _buildState(), _vnToolbarStatesEqual()
<vn-grid-toolbar> recomputes its state on every grid event it listens to. state.selectedKeys and state.selectedRows are lazy getters, materialised only if something reads them, and the state is copied with its property descriptors so a copy does not invoke them. Selections are compared by getSelectedCount(), selectAllActive and a revision counter the toolbar bumps on each selection change, not by content. This mirrors the lazy getters in the grid's own selection-changed event. See Toolbar implementation.
With every row selected, a recompute costs 0.4 ms at 1M rows (was 37.8 ms, four to seven times per load) and 0.28 ms at 100k (was 4.7 ms).
4.4 Appended pages are merged into the sort order
Where: features/sorting.feature.js, mergeAppendedRows()
With a client-side sort active, appendRows() sorts the new page on its own and places each of its rows at the upper bound of its value among the existing rows, in one O(n + p) copy, instead of re-sorting everything per page. Placing ties after existing rows gives the same order as a stable full sort (the grid relies on Array.prototype.sort() being stable, which it is in every supported engine). The merge runs only when displayRows is known to be the sorted order of the rows before the append, recorded per array in a WeakMap; otherwise, and while grouping is active, the grid re-sorts in full. See Sorting § 10.2.
loadDataProgressively() of 100k rows in 1,000-row chunks, sorted on Salary: 5.7 → 3.45 s, 29 long tasks → 1.
Guard: tests/node/sorting-append-merge.test.js compares the merged order with a full sort after every append over randomised data.
5. Sorting and grouping
5.1 One reorder per operation
Where: vanilla-grid-element.js and vanilla-grid.js, clearPersistedSettings(); vanilla-grid.js, setColumns(), setRows(); features/grouping.feature.js, realignRenderEntriesForDisplayRows()
Operations that change several things at once (the toolbar's "Reset grid layout" is the extreme case) reorder the data once, off-thread where possible:
- The reset reloads only when it must: when it cleared a column filter, a search term or a server-side sort. Otherwise the in-memory reset is already complete. See Local Storage Settings § 6.5.
- Nothing reorders ahead of a reload.
clearPersistedSettings({ deferToReload: true })clears sort and group state without reordering and parks the declarative sort and grouping;setRows()applies them in a single reorder. setRows()reorders on the shared bracket (runReorderPipeline()), so a large load gets the shimmer and, when eligible, the sort Worker. BelowsortShimmerThresholdit stays synchronous, and a load with nothing to order skips the bracket. See Sorting § 7.2.1.- The grouping projection is built once per reorder.
realignRenderEntriesForDisplayRows()leaves the build to the reorder'sfinishwhenever grouping is applied, and otherwise re-aliases without allocating. This saves ~600 ms at a million rows on every grouped sort and group change.
At a million rows the reset gesture went from ~4.1–4.3 s of blocked main thread to ~0.44 s. Guard: tests/playwright/grid-reset-layout-requery.spec.js (300,000 rows, 450 ms ceiling).
5.2 A group change shows its new state immediately
Where: features/grouping.feature.js, setGroupState(); features/viewport.feature.js, _onViewportResized()
This is about what is on screen while a reorder runs off-thread, not about blocked time:
- The visible column set depends only on the group state, so
setGroupState()syncs it in its prologue, alongside the chip, instead of in the reorder'sfinish. See Grouping § 6.1. - While
isLoadingis true,_onViewportResized()re-paints the loading skeleton at the new size instead of rendering rows over it. Mounting the group bar resizes the viewport, and previously that removed the shimmer ~25 ms into the reorder. The rule covers every load that overlaps a resize. See Row Virtualization § 1.12.1.
| sampled every frame | 1,000,000 before | now | 300,000 before | now |
|---|---|---|---|---|
| grouped column gone | 1720 ms | 73 ms | 327 ms | 71 ms |
| frames showing stale rows while loading | 76 | 0 | 7 | 0 |
Guard: tests/playwright/grouping-transition-shimmer.spec.js fails if any frame shows real rows over a raised loading state.
5.3 Group boundaries are found by galloping search
Where: features/grouping.feature.js, _findRunEnd()
displayRows is sorted by the group keys, so each group is a contiguous run. The end of a run is found by probing start + 1, +2, +4, … until a row differs, then binary-searching the gap: about 2·log₂(run) comparisons per run, and one for a run of one, instead of one per row. A build without aggregates never reads the rows between probes. This applies to every full projection build: a fully collapsed million-row grid builds in 0.1 ms (was 184 ms), and "Collapse all" dropped from ~300 ms to one frame. See Grouping § 3.2.
5.4 Toggling one group splices the projection
Where: features/grouping.feature.js, _spliceToggle()
A caption toggle, or expandGroup() / collapseGroup() on a projected caption, changes one contiguous block of renderEntries, so the grid removes or inserts that block and the matching part of the data-index map: O(the block) plus an O(n) pointer copy, with no comparator call outside the block. A toggle under a collapsed ancestor changes state only. Aggregate extremes are refolded lazily on the next auto-fit read. See Grouping § 4.
Call to next painted frame, large-dataset-js, two aggregates, median of 5 (the floor is about two frames, ~33 ms):
| Rows | Levels | Collapse all | Expand all | Toggle one group |
|---|---|---|---|---|
| 100k | 2 | 33 → 33 ms | 72 → 38 ms | 53–66 → 32–33 ms |
| 300k | 2 | 84 → 33 ms | 183 → 41 ms | 169–189 → 33–34 ms |
| 1M | 2 | 300 → 33 ms | 630 → 76 ms | 592–627 → 36–54 ms |
| 1M | 3 | 294 → 33 ms | 892 → 103 ms | 825–899 → 33–42 ms |
Guard: tests/node/grouping-toggle-splice.test.js checks that the spliced result equals a full build after every step of randomised toggle sequences.
5.5 Aggregates visit each row once
Where: features/grouping.feature.js, buildRenderEntries(); aggregate-registry.js
An aggregate is the one part of the projection build that reads every row, and in grouped (sorted) order each read is a cache miss. All aggregated columns and all open levels are therefore stepped in a single visit per row, in displayRows order. A separate accumulation loop per column measured +110 ms per column, three times the shared visit. A collapsed branch is still visited with emit: false on a full build, because its own total must exist, but nothing is pushed to the projection.
Build time at a million rows, sum, median of five:
| no aggregate | 1 column | 2 columns | 4 columns | |
|---|---|---|---|---|
| Country, expanded | 41 ms | 204 ms | 238 ms | 278 ms |
| Country ▸ City, expanded | 49 ms | 334 ms | 365 ms | 433 ms |
| Country ▸ City, collapsed | 0.1 ms | 260 ms | 298 ms | 355 ms |
An aggregate change runs on the reorder bracket with sortShimmerThreshold, like a sort. Reducers stay on the main thread because host-registered reducers cannot be sent to a Worker.
Guard: tests/node/aggregates-feature.test.js records the reads a build makes and fails unless each row is read once, in order, with every aggregated column read in that visit.
5.6 Expand and collapse reuse aggregate results
Where: features/grouping.feature.js, buildRenderEntries({ reuseAggregates: true })
Collapsing changes which entries are projected, never which rows a group holds, so the four collapse paths (caption toggle, expandGroup() / collapseGroup(), Expand all / Collapse all) reuse the stored aggregate results. They run no accumulator, skip collapsed branches, and refold only the per-column extremes over the projected footers: O(projected groups). Reuse is guarded by a reference check on the configured aggregate set and falls back to a full build if a projected group has no stored result. See Grouping § 4.
At a million rows with a distinct count on Email, a toggle went from ~3.7 s to ~0.55–0.8 s and Collapse all from ~3.8 s to ~390 ms, before § 5.4 reduced a toggle further.
6. Excel export
6.1 The workbook is streamed
Where: features/excel-export.feature.js
The grid writes .xlsx itself instead of building it in memory with a third-party library:
- Rows are read in chunks of at most 5,000 rows, or fewer once a chunk has taken 8 ms, and the producer yields to the main thread between chunks (
VanillaGridYield.yieldToMainThread()). - Each chunk becomes sheet XML and is compressed with
CompressionStream('deflate-raw'), so only compressed bytes are kept. From 5,000 rows the writer runs in a Worker; per-cell style ids travel in a transferredUint32Array. - At most two chunks are unacknowledged, which bounds memory.
- A Worker failure is not retried on the main thread. The export rejects with a coded error, and the overlay shows progress, errors and a Cancel button.
- Rows past Excel's 1,048,576-row limit continue on additional sheets.
See Export to Excel.
large-dataset-js, 21 columns |
Total | File | Peak renderer | Longest main-thread task |
|---|---|---|---|---|
| 100,000 rows, previous library | 40.5 s | 91.6 MB | 1,939 MB | 455 ms |
| 100,000 rows, now | 3.1 s | 14.2 MB | 507 MB | none over 50 ms |
| 200,000 rows, previous library | failed after ~150 s, 108 s frozen | – | – | 108 s |
| 1,000,000 rows, now | 31.4 s | 143 MB | 1,660 MB | none over 50 ms |
The previous library could not go past about 140,000 rows: it built the ZIP through a JS array holding one element per byte, and kept one object per cell.
Guard: tests/playwright/excel-export-large.spec.js exports 150,000 rows and fails on any main-thread task over 150 ms.
6.2 The full-fetch drain pages bigger than the grid scrolls
Where: vanilla-grid.js _materializeMatchingRows(), fetchAllRows() in data-managers/odata-data-manager.js and data-managers/graphql-data-manager.js
An export of every matching row (or of a select-all) first drains the rows through the DataManager, one sequential request per page. A drain has no screen to fill, so drainPageSize (the export's option or the grid's export.drainPageSize, and materializeSelectedRows({ drainPageSize })) lets it request bigger pages than the DataManager's pageSize scroll pages. people-cities-js scrolls in 1,000-row pages and drains in 5,000-row pages.
50,000 rows from MINT (people-cities-js's export cap) |
Requests | Run 1 | Run 2 | Slowest request |
|---|---|---|---|---|
| pages of 1,000 | 50 | 7.5 s | 8.7 s | 0.43 s |
pages of 5,000 (drainPageSize: 5000) |
10 | 5.6 s | 5.5 s | 0.69 s |
A single 1,000-row page is 210 KB and takes 0.19 to 0.21 s; a 5,000-row page is 1.05 MB and takes 0.71 to 0.79 s. MINT spends most of each request producing rows, so five times fewer requests save about 30%, not 80%. These figures come from Node fetch on a desktop machine against https://people-cities-app.mthome.org/odata-c/users (X-MU-Environment: metrical, no sort or filter, 500,000 rows in total), not from a browser: they leave out browser JSON parsing and the export itself.
7. Loading and build
7.1 Scripts load without blocking the parser
Where: vanilla-grid.js, bootstrap IIFE
Feature scripts are injected as dynamic <script> tags with async = false, which preserves order without document.write. window.VanillaGridReady (or <vn-grid>.ready()) resolves once every feature has loaded. Pages that need everything in one request use vanilla-grid.bundle.js, which inlines every dependency and sets window.VanillaGridSkipAutoload = true.
7.2 No spreadsheet library on page load
Because the export writes .xlsx itself (§ 6.1), no page downloads or evaluates a spreadsheet library, whether it exports or not. Removing it cut boot script evaluation from 62.4 to 47.5 ms and transfer from 2,296 to 1,903 KB (large-dataset-js, from source, average of 3 boots). It was 425 KB raw, 142 KB gzipped.
7.3 Hot paths are excluded from obfuscation
Where: build.js, BUNDLE_FAST_PATH
Under npm run build:obfuscate, files that run per row, per cell or per comparison use the fast profile (minify and mangle only) instead of the heavy one, which costs about an order of magnitude on a hot loop. The list includes rendering, viewport, sorting and its comparator, grouping, aggregate-registry.js, column-access.js, intl-cache.js, selection and the Excel export producer; build.js gives the reason for each. For example, a million-row selectAll() blocked for 5.0–5.1 s while selection.feature.js was on the heavy profile.
Listing a loop's file is not enough: what the loop calls per row must be defined in a fast chunk too. vanilla-grid.js and vanilla-grid-element.js stay heavy, and in a heavy function every property name is fetched through the obfuscator's string decoder, so a hook written there as an arrow, a forwarding method there, or a getter arrow read per row costs that decoder on every row. So:
- Hooks are bound fast-chunk methods. The tree build's key hook and a
StaticDataManager'skeyOfare the selection feature'sresolveRowKey(), bound; itsparentKeyOfis the tree feature's, bound. The viewport API's key map and the select-all materialize filter (notExcludedRowFilter()) call the selection feature directly. The Gantt'sparentKeyGettercomes fromtasks.feature.js(parentKeyGetterOf()). - Configuration is passed as values. The selection feature takes
rowKeyFieldandrowKeyGetteras values, set once, so resolving a key calls only the host's ownrowKeyGetter. - Many lookups are one call. A follower indexing many rows calls
getTreeRowPositions(keys)once instead ofgetTreeRowInfo()per key (Tree Rows § 8).
Measured at 1M rows in headless Chromium, the source tree against an obfuscated dist/ build before these changes: the tree build took 417–427 ms against 1,358–1,422 ms (file-system-js), the selection key map 236–259 ms against 843–875 ms, the StaticDataManager's tree key index 269–281 ms against 2,009–2,163 ms, and the Gantt's link index rebuild 359–369 ms against 2,312–2,371 ms (project-tasks-js).
Known costs
The costs that remain, and why:
- Building the grouping projection is one synchronous scan: 210–280 ms at a million rows with two aggregates configured. It is the largest synchronous block of a grouped sort, reload or search clear, and runs under the shimmer. Entries are row references, so a Worker cannot build them, and chunking would require rendering a half-built projection or holding two.
- Scaled mode costs about 21 ms of main-thread work per frame against 13 ms in natural mode, because every pass moves the whole pool block and the visible rows are laid out and repainted instead of scrolled by the compositor. See Row Virtualization § 1.5.
- Expand all must push every row into the projection: 57–124 ms to paint at a million rows. This is below the ~150 ms at which a busy indicator would be warranted.
- A group change's first paint takes ~70 ms instead of ~5 ms, because § 5.2 renders one screenful before the shimmer goes up (~63 ms at 300,000 rows). Avoiding that render would need a hook ahead of the reorder bracket shared with sorting.
Measurement method
Measured on an AMD Ryzen 7 5700U in Playwright's headless Chromium shell at 1400×900, against the unminified source tree with caching disabled. Unless stated otherwise the fixture is samples/large-dataset-js/?rows=N (&group=none for a flat grid): 21 data columns plus the selection column, a 37 px row (Fiori theme) and a 61–64-row pool. Column work also used northwind-orders-js (25 columns, 51 pool rows) with its backend stubbed by tests/playwright/_northwind-stub.js.
- Scrolling dispatches one
WheelEvent(deltaY120) on the viewport per animation frame: 240 frames after a 60-frame warm-up, which driveshandleWheel → applyScrollDelta → scroll → handleScroll → renderVisibleRows. Per-frame figures are deltas of the DevTools Protocol'sPerformance.getMetricscounters divided by the frame count. - Forced layouts are attributed with a Chromium trace including
disabled-by-default-devtools.timeline.stack. - Data operations are timed from the call to a settled grid: not busy, and the projection unchanged for 300 ms. "Long tasks" are
PerformanceObserverlongtaskentries. - Memory is
performance.memory.usedJSHeapSizeafter forced garbage collection.
The headless shell rasterizes in software, which makes painting expensive, so absolute frame times are pessimistic compared with a GPU-backed browser. Layout counts and relative differences carry over. Assume slower hardware is 2–4× worse.