Birch UI v0.1
Pricing

Performance & workersPivot Studio

How Pivot Studio handles a million records, aggregating in a Web Worker with the worker option, and running the headless pivot engine in Node, workers and tests.

Open .md

Pivot Studio is built to pivot large datasets in the browser. It encodes each field once when the data is loaded, then aggregates on typed arrays, so changing the report re-aggregates without re-reading the records.

Measured performance#

The package README reports, for Node on a development machine:

1,000,000 records pivot into 3 row levels × 2 column levels × 3 measures in about 0.6 s the first time (type detection, date parsing and encoding included) and about 0.15 s for each change after that.

The package's performance test enforces a 2-second budget for that case. Timings in browsers depend on the device and on your data's shape, so measure on your users' hardware.

Some changes are cheaper than others:

Change Work
Loading data Parse, detect types, encode every field
Adding or removing fields, filters, aggregations Re-aggregate the encoded data
Expanding or collapsing members, layout and totals options Rebuild the visible table from the existing aggregates
Scrolling Birch UI Grid renders only the visible rows and columns

pivotUpdated reports how long each update took, which is useful for monitoring real-world performance:

TypeScript
studio.on('pivotUpdated', ({ rowCount, columnCount, recordCount, durationMs }) => {
  telemetry.record('pivot_update_ms', durationMs, { rows: rowCount, columns: columnCount, records: recordCount });
});

Aggregating in a Web Worker#

With large data, aggregation can take long enough to make the page feel stuck. Set worker: true to run it in a Web Worker:

TypeScript
createPivotStudio(container, {
  data: salesFor2026,
  report,
  worker: true,
});
  • The worker is created from a Blob URL built from the same bundle, so there is no extra file to host or configure in your bundler.
  • While a computation runs, the table shows a "Calculating…" overlay and is marked aria-busy.
  • When several changes come in quickly, only the latest result is shown.
  • Loading and encoding the data still happen on the main thread; the worker does the aggregation, which is the part that repeats on every change.

Workers need Worker, Blob and URL.createObjectURL. If they are not available or the worker cannot be created, Pivot Studio aggregates on the main thread without a message. If the worker fails while running, for example because a Content Security Policy blocks blob: workers, Pivot Studio prints one console warning, stops using the worker and computes on the main thread. To allow the worker under a CSP, add blob: to worker-src:

text
Content-Security-Policy: worker-src 'self' blob:

update({ worker: false }) and update({ worker: true }) switch at runtime.

When to use the worker#

Records Recommendation
Up to about 100,000 Main thread; updates are fast enough not to notice
100,000 to 1,000,000 worker: true keeps the page responsive while users rearrange fields
More than 1,000,000 Aggregate on the server first, or load a filtered subset; also consider the headless engine below

The headless engine#

createPivotEngine() is the same engine without the UI. It runs in Node, in your own workers and in tests, and produces the same matrices, records and workbooks as the widget:

nightly-store-report.ts
import { writeFile } from 'node:fs/promises';
import { createPivotEngine } from '@birchui/pivot-studio';
import { writeXlsx } from '@birchui/excel';

const sales = await loadSalesFromWarehouse({ from: '2026-01-01', to: '2026-06-30' });

const engine = createPivotEngine({
  data: sales,
  report: {
    slice: {
      rows: [{ field: 'region' }, { field: 'store' }],
      columns: [{ field: 'orderDate.month' }],
      values: [{ field: 'revenue', format: { style: 'currency', currency: 'GBP', decimals: 0 } }, { field: 'units' }],
    },
  },
  locale: 'en-GB',
  onWarning: (message) => console.warn(message),
});

const matrix = engine.getMatrix({ formatted: true });
const workbook = engine.buildWorkbook({ sheetName: 'H1 2026', title: 'Store sales, first half 2026' });
await writeFile('store-sales-h1-2026.xlsx', await writeXlsx(workbook, { licenseKey: process.env.BIRCHUI_LICENSE_KEY }));

const leedsOrders = engine.drillThrough(['North', 'Leeds Trinity']);
PivotEngineOptionsinterface@birchui/pivot-studioFull reference
PropertyTypeDescription
dataoptionalreadonly TRecord[] | string—
dataFormatoptionalDataFormat—
csvDelimiteroptionalstring—
dataLimitsoptionalPartial<DataLimits>—
fieldsoptionalFieldDefinition[]—
reportoptionalPivotReport—
localeoptionalstring—
translateoptionalTranslate—
onWarningoptional(message: string) => void—

The engine's main methods:

Method Description
setData(data, options?) Load records, CSV or JSON, like the widget's setData()
setReport(report), getReport() Load or read the report
getFields(), getMembers(field) Detected fields and a field's members
compute() Aggregate and return the view
getMatrix(options?) The pivot as a 2-D array, computing first if needed
buildWorkbook(options?) An XlsxWorkbook with every row member, outline levels and number formats; write it with writeXlsx() from @birchui/excel
drillThrough(rowPath, colPath?) The records behind a cell
setExpanded(axis, path, expanded), setAllExpanded(axis, expanded) Expansion state, as in the widget

aggregateCube() is the aggregation kernel itself, a pure function on typed arrays, exported for advanced cases such as running the aggregation in a worker pool of your own.

Tips for large datasets#

  • Load only the fields you need. Every field is encoded, so dropping unused columns before loading saves memory and load time.
  • Keep high-cardinality fields out of Columns. A field with thousands of members, such as an order ID, makes thousands of columns. Use it in Values with distinctCount, or in Rows with a top-N filter.
  • Send numbers and ISO dates. Numeric text and other date notations take longer to parse.
  • Reuse the widget. Call setData() and setReport() instead of recreating the widget, so the grid, panel and worker are kept.

↑ ↓ to move, Enter to open, Esc to close