Benchmarks

Numbers for the engine in Rust and through the JavaScript binding, with the machine, the versions and the commands to reproduce them.

These numbers are a reference for the order of magnitude and for catching regressions, not a promise. Run them on your hardware before you size anything.

Machine and versions#

CPUAMD Ryzen 7 7435HS (8 cores, 16 threads), laptop, frequency scaling on
Memory15 GiB
OSLinux 7.3.3 (CachyOS)
Rust1.99.0, --release bench profile
criterion0.5.1
Node22.23.4
Bun1.4.4
Strig0.6.1 plus the unreleased changes of the day, tz feature on as by default

A laptop under normal desktop load: expect 10% to 20% of noise between runs on the slower cases. Two runs of the Rust suite gave 12.8 and 14.7 µs for the same case. Treat smaller differences as noise.

What is measured#

All cases share one catalog (document.view and document.edit on document and project, broad target org).

CaseWhat it does
decide/simpleOne decide against one role grant on the org.
decide/conditions_and_relationsOne decide of document.edit against about 1,000 grants: one guarded by an eq and a time_between condition, one through the editor relation (50 tuples), 1,000 unrelated grants the engine has to skip and, in Rust only, 10 deny locks.
list/planlist of what the subject can edit among documents: the plan of the filter, with the same grants and 50 tuples.
list/resolve_10k_rowslist plus resolving the filter over 10,000 resources in memory (in JS, one call with resources).
apply/governanceOne Add of a grant through Governance with CatalogConformance and NoSelfManagement, no audit.
apply/governance_with_auditThe same, audited at the standard level. In Rust to a JsonLinesAudit over io::sink(). In JS the record is built and returned, with no sink.
apply/governance_with_audit_sinkJS only: the same, with an auditSink that does nothing, to price the call into JavaScript.

The JS numbers include what crosses the boundary: the request and the result are serialized as JSON, and a decide takes the Context that already holds the grants. That cost, not the decision, is most of the difference between a Rust call and a JS call on the small cases.

Rust#

Median of the criterion estimate.

CaseTime
decide/simple479 ns
decide/conditions_and_relations14.7 µs
list/plan41.1 µs
list/resolve_10k_rows4.02 ms (about 400 ns per row)
apply/governance410 ns
apply/governance_with_audit1.01 µs

The cost of a decision grows with the grants that name the same permission and kind, not with the size of the catalog: the 1,000 unrelated grants are most of what separates the two decide cases. The audit adds about 0.6 µs per change at standard. The forensic level also hashes with SHA-256, so it costs more. Listing filters 10,000 rows in memory in the time of about 8,000 single decide calls of the simple case. strig-postgres turns the same plan into SQL instead of resolving rows in memory.

JavaScript#

Median of seven samples of 500 ms each, after 300 ms of warm-up. This table was taken before the boundary change described below; decide and apply are faster now, and the second table has the new numbers for the small cases.

CaseNode, nativeNode, wasmBun, nativeBun, wasm
decide/simple16.1 µs19.6 µs12.6 µs22.0 µs
decide/conditions_and_relations30.9 µs42.4 µs31.6 µs41.0 µs
list/plan248 µs300 µs232 µs303 µs
list/resolve_10k_rows87.1 ms92.7 ms77.2 ms103 ms
apply/governance28.9 µs34.1 µs24.0 µs39.1 µs
apply/governance_with_audit40.3 µs48.4 µs36.4 µs53.0 µs
apply/governance_with_audit_sink45.3 µs57.3 µs38.4 µs82.0 µs

Reading them:

  • Before the change, the native module cost 16 µs for a simple decision, most of it the boundary, against 0.5 µs in Rust.
  • The wasm backend is about 1.2 to 1.4 times slower than native on Node. Bun's wasm shows the widest spread, so treat its figures as rough. This is also what a Linux musl or Alpine install runs on (JavaScript).
  • list/resolve_10k_rows includes sending 10,000 resources into the engine. It is the cost of an exact in-memory filter from JS.
  • An auditSink adds one JavaScript call per record, about 5 µs on Node native.

JavaScript: the boundary, before and after#

A check on Node native spent its time like this, when decide/simple took 16.1 µs against 0.48 µs in Rust:

StepCost
An empty N-API call0.25 µs
Reading the request object, property by property, about 0.7 µs per leafabout 12 µs
The engine0.5 µs
JSON.stringify of the same request0.77 µs
Parsing that string in Rust0.73 µs

The Context already held the grants on the Rust side, so the grants were never the cost; the request and the response were. The wasm glue showed the same shape (check 15.6 µs).

The binding now crosses with one string (JSON.stringify in, JSON.parse out for decide and explain), and checkMany spreads the call over a batch. With 100 requests per batch (median):

CaseNode, nativeNode, wasmBun, nativeBun, wasm
decide/simple6.5 µs9.3 µs5.1 µs8.6 µs
check/simple3.5 µs4.5 µs2.6 µs3.3 µs
checkMany/simple, per decision2.5 µs3.7 µs2.5 µs3.2 µs

A single decide stays above 2 µs on Node native. A check costs at least 0.77 µs to stringify, 0.73 µs to parse, 0.49 µs in the engine and 0.25 µs for the call, about 2.3 µs, and a decide adds the building, serialising and parsing of the Decision, about 1.6 µs. Going lower needs a request that is not text, such as handles to a subject and a resource prepared once, which is a different API. For one request, check is the cheapest answer. For many, checkMany.

Reproduce#

Rust, from the repository root:

Terminal
export CARGO_TARGET_DIR=/path/with/space   # optional: the release build and criterion need a few GB
cargo bench -p strig --bench engine

criterion prints the estimate per case and keeps its reports under target/criterion. cargo bench -p strig --bench listing prints listing against a per-row check for growing tables, and the cost of each kind of condition.

JavaScript, from crates/strig-node/js:

Terminal
sh ../scripts/build.sh all        # the native module and the wasm
npm ci
npm run build:ts
node bench/bench.mjs              # both backends; --backend native|wasm picks one
bun bench/bench.mjs

The Benchmarks workflow in GitHub Actions, run by hand, does the same on a GitHub runner. It is not part of CI, and runner numbers are noisier than a dedicated machine, so compare only runs from the same kind of machine.