Skip to content

Docs · Getting started

Introduction

What Vectro is, what it is for, and how it differs from a database you run next to your app.

Vectro is an analytics engine that lives inside your JavaScript program. You give it columns of numbers, text and dates; it filters, groups, joins, sorts and answers SQL over them, on every core of the machine, without a server and without a native addon.

import { Engine, sql } from 'vectrojs';

const engine = new Engine();
const orders = engine.table({
  region: ['EU', 'US', 'EU', 'APAC', 'US', 'EU'],
  price:  [120, 80, 45, 300, 99, 15],
  qty:    [2, 1, 4, 1, 3, 10],
});

console.log(sql(`
  SELECT region, COUNT(*) AS n, SUM(price * qty) AS revenue
  FROM orders GROUP BY region ORDER BY revenue DESC`, { orders }).toRows());

await engine.close();

Where it runs

  • Node 20 and later: one worker thread per core, sharing one block of memory with your program.
  • Browsers: Web Workers on every core when the page is cross-origin isolated, one thread otherwise. Chrome, Safari and Firefox are checked on every change.
  • Edge runtimes such as Cloudflare Workers: one thread, from an 11 KB precompiled WebAssembly module and a vectorized interpreter where code generation isn’t allowed.

The same API works in all three; the browser and edge builds use the *Async methods.

How it works, in one paragraph

Data is kept in columns in WebAssembly memory. Each query is compiled into a SIMD WebAssembly loop when it is first seen, then run on every core at once, each core taking its own share of the rows. Group-bys with a few groups add into per-thread totals; with millions of groups the rows are split by key range so each thread owns its own groups. Files bigger than memory are read one chunk at a time, and the min and max kept for every block of rows let a query skip what it doesn’t need.

When to use it

  • Dashboards and reports computed in a Node service, without shipping data to a warehouse.
  • Analytics in the browser: filtering and grouping millions of rows on the user’s machine.
  • Files bigger than memory, one machine, no cluster: .vectro datasets.
  • Serving tables to BI tools (Power BI, Tableau, Metabase, Grafana) over the PostgreSQL protocol.

When not to

Vectro is not a transactional database: there are no updates in place, indexes or concurrent writers. Data is held in memory (or read from files); an engine holds at most 4 GB at once. For that kind of work use PostgreSQL or SQLite, and point Vectro at the data you want to analyse.

How fast

Measured against DuckDB 2.0 on the same machine, with the same SQL and the same answers: faster on all 20 benchmark queries over 10M rows, and level or faster on 7 of 8 queries over a billion rows on disk. See the benchmarks, or race them yourself in this browser.

Next: install it.