Performance and scale

PrismBI keeps everything in the browser. This guide covers how the engine handles large tables, what to expect at a million rows, and how to move work off the main thread.

Try it with npm run dev, then open /perf.html. That page generates 100k to 1M rows, prints cold query timings, and runs a simulated live feed into the model.

What the engine does for you #

Numbers #

npm run bench generates a star schema and times each query cold, with caches cleared before each run. The schema is a fact table, 400 products, 40 regions and a two-year calendar. The query filters to one year, about half the rows. Timings are from Node 18 on a laptop:

Query200k rows1M rows
Category × sales and average order value (12 groups)47 ms191 ms
Product × region, 16k groups58 ms (per-group engine: 11.3 s)99 ms
Day × sales, 365 groups8 ms12 ms
Product × region, CALCULATE filter27 ms (per-group engine: 11.6 s)79 ms
Day × YTD (time intelligence)15 ms (per-group engine: 0.65 s)21 ms (was 193 ms)
Year × month × sales, last year and growth17 ms (per-group engine: 47 ms)46 ms

Each query has a time budget in bench/scale.test.ts (about three times these figures), so npm run bench fails on a real regression.

Generating and loading 1M rows takes about 0.75 s. Warm queries (same filters again) come from the caches in well under a millisecond.

Pre-aggregated results can differ from a row-by-row scan in the last floating-point digits, because the same values are added in a different order. Displayed values are unaffected.

Compare the two paths yourself; they return the same rows:

▶ Run in playground
import { setFastQuery } from '@prismbi/prismbi';

const spec = { groupBy: ['Date[Year]', 'Date[MonthNumber]'], values: ['Total Sales', 'Sales LY', 'Sales YTD'], totals: true };
const run = (mode) => {
  setFastQuery(mode);
  const t = performance.now();
  const r = model.query(spec);
  return { ms: Math.round(performance.now() - t), rows: r.rows.length, first: r.rows[0] };
};
const result = { singlePass: run('always'), perGroup: run('off') };
setFastQuery('auto');
return result;

Rendering at scale #

The scale demo: 250,000 rows, a dense line chart, 8,000 scatter points and a virtualized table

Off the main thread #

@prismbi/prismbi/worker (about 2 KB) runs the model in a Web Worker. Build or load the model inside the worker, then talk to it from the page:

// model.worker.ts
import { serveModel } from '@prismbi/prismbi/worker';
import { loadCsv } from '@prismbi/prismbi/connectors';
import { DataModel } from '@prismbi/prismbi/core';

const model = new DataModel().addTable('Sales', await loadCsv('/sales.csv')).addMeasure('Total', 'SUM(Sales[Amount])');
serveModel(model);
// main thread
import { createWorkerEngine } from '@prismbi/prismbi/worker';

const engine = createWorkerEngine(new Worker(new URL('./model.worker.ts', import.meta.url), { type: 'module' }));
const ctrl = new AbortController();
const result = await engine.query({ groupBy: ['Sales[Region]'], values: ['Total'] }, ctrl.signal);

The engine API is asynchronous, and every method returns a promise:

MethodDoes
query(spec, signal?)Runs a QuerySpec and returns rows and totals.
evaluate(expression, filters?, signal?)Evaluates a scalar expression.
evaluateTable(expression, filters?, signal?)Evaluates a table expression (DAX EVALUATE).
addTable(name, rows, schema?), refreshTable(...), appendRows(name, rows, options?)Changes table data.
addColumns(name, columns, schema?, { transfer? })Adds a table from column arrays, moving numbers, dates and text codes to the worker as transferred buffers (see below).
addMeasure(def)Adds a measure.
setRoles(roles, options?)Switches row-level security roles.
metadata()Returns tables, columns, measures and relationships, without rows.
dispose()Stops the engine and terminates the worker.

Filters must be filter specs ({ target, op, value }), because compiled filters can't be copied to another thread. Requests run in order. Aborting a request rejects it at once with an AbortError, and the worker skips it if it hasn't started.

createLocalEngine(model) has the same API on the current thread, for tests, server rendering or small models.

Large tables: send columns, not rows. addTable copies every row object to the worker (structured clone). addColumns packs number and date columns as Float64Arrays and text as Int32Array codes plus a dictionary, and transfers the buffers, so nothing is copied; the worker adopts them as the table's numeric and dictionary views, which also makes the first query faster. In Node, loading 1M rows of four columns over a MessageChannel took about 1.2 s instead of 11.5 s, and the first grouped query about 250 ms instead of 600 ms.

await engine.addColumns('Sales', {
  Amount: amounts,            // Float64Array or number[]
  Region: regions,            // string[] → codes + dictionary
  OrderDate: dates,           // Date[] → epoch ms
});

Typed arrays you pass are moved, and are empty afterwards; pass { transfer: false } to send a copy instead. Arrays backed by a SharedArrayBuffer (available when the page is crossOriginIsolated) are shared rather than moved. packColumn and addPackedTable are exported for building the same tables yourself.

Multi-worker parallel execution pool #

For multi-million row datasets where concurrent visuals or animated sliders send parallel queries, @prismbi/prismbi/worker provides createWorkerPool:

import { createWorkerPool } from '@prismbi/prismbi/worker';

const pool = createWorkerPool({
  workerFactory: () => new Worker(new URL('./model.worker.ts', import.meta.url), { type: 'module' }),
  size: navigator.hardwareConcurrency || 4,
});

// Pass `pool` as `engine` to your report:
const report = new Report(el, { model, engine: pool, pages });

Reports on the worker #

Pass the engine to a report and every visual query runs in the worker:

const report = new Report(el, { model, engine, pages });

Visuals render asynchronously. On first load a visual shows a shimmer. After that, a re-query keeps the previous result on screen, dimmed, until the new one arrives, and superseded queries are cancelled.

Slicers and queries without measures still run on model on the page, so slicer tiles appear instantly. The page also uses model for metadata: field lists, slicer domains, colours.

Keep the two models in step. Build both from the same code, and apply live rows to both: model.appendRows(...) plus engine.appendRows(...). The /perf.html demo has a "Queries in a Web Worker" switch that does exactly this.

Tips #