Skip to content

Library architecture ​

grABM is one private ESM package with two main classes and JSON-compatible contracts.

  • Scenario validates immutable population, demographic profiles, and model settings.
  • Simulation combines that configuration with a graph and facilities. Each run() creates fresh execution state and takes explicit seed and time settings.
  • RunResult preserves the complete input snapshot, effective agent profiles, outputs, diagnostics, and provenance. Analytics, playback, and codecs consume this data.

Internally, contracts, event execution, routing, workers, analytics, and playback are organized by responsibility and use relative imports. Execution internals are private. The engine has built-in algorithms configured through data, without a public registry or application-specific source conversion layer.

Worker mode uses the same Simulation API. Each run owns and releases one browser worker. Local execution works in Node without DOM globals or rendering dependencies. Optional Three.js and Plotly imports remain separate. Applications own source conversion, renderers, databases, UI, and hosting.

See the import map, first simulation, and generated exports.

Performance baseline ​

Run npm run benchmark for construction and local execution with 100, 1,000, and 10,000 agents. The fixture uses two facilities and a 100-metre edge, with enough capacity for every agent to make one trip. The command reports medians of three runs.

Measurements from 20 September 2026, Node 24.13.0 on macOS arm64:

Agents / tripsBefore refactorCurrent APISampled additional heap, before / current
1005.0 ms14.0 ms2.2 / 3.7 MiB
1,00034.5 ms43.9 ms13.6 / 11.6 MiB
10,000291.0 ms341.7 ms64.0 / 58.6 MiB

The current path includes immutable configuration construction, profile resolution, and event-loop yields for local cancellation. The old path measured direct execution. Heap is sampled at progress callbacks and completion after a pre-run garbage collection; it is neither peak RSS nor a guaranteed memory limit. This small graph does not measure large-network routing, serialization, analytics, playback, or worker startup/transfer. Use representative host graphs before setting a production population target. Timing is recorded for comparison, not asserted in CI.

See future work for the proposed benchmark expansion and the criteria for adding execution or storage complexity.

Full-day execution and dataset measurements ​

A single measurement on Apple M4 Max (16 CPUs), macOS arm64, Node 24.13.0 used the synthetic eight-node, nine-edge demo with seven destinations, three profiles, seed 42, and a 24-hour horizon. It exercises multiple trips per person; it is not a city-scale network or an empirical model-validation claim.

AgentsTripsExecutionDataset preparationLocal first-frame data + samplingDataset resources
1,0005,700351 ms560 ms9.6 ms2.7 MB
10,00057,0003.38 s5.01 s27.2 ms24.2 MB

The 10,000-agent run sampled 129 MiB JavaScript heap after execution and 187 MiB after analysis; the process-wide RSS high-water mark reached 579 MiB across both workloads. These are different measures. They are not a guaranteed capacity limit or a measured peak for each individual stage. Five local-file seeks ranged from 3.0 to 42.0 ms, including position sampling. Browser rendering, network latency, and worker-transfer costs are excluded from these file-reader measurements.

Run npm run benchmark to reproduce the stages. Set BENCHMARK_AGENTS=50000 for a larger opt-in workload. The recorded single samples are in the benchmark report. Ordinary CI verifies correctness rather than machine-dependent timing thresholds.

The report also separates source opening, first-frame sampling after opening, and summed filesystem read time. Reads can overlap with prefetch; their sum is not an end-to-end transport latency measurement.

Documentation for the grABM library.