Skip to content

VrilLabs/warp-core

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

@kronos/warp-core

Sub-microsecond reactive runtime β€” SharedArrayBuffer-backed signals with true cross-thread propagation, zero postMessage overhead, and fleet-aware effect scheduling.

Why

Existing signal libraries (Alien Signals, Preact Signals, SolidJS) operate within a single thread. Cross-worker reactivity requires serializing dependency graphs through postMessage, adding milliseconds of overhead per notification.

@kronos/warp-core eliminates this entirely:

Feature Traditional Signals Warp Core
Cross-thread propagation postMessage (1-5ms) Atomics.notify (~0.1ΞΌs)
Memory model Per-thread copies Single SharedArrayBuffer
Dependency tracking Per-thread graph One arena, all threads
Effect scheduling Microtask queue CAS + waitAsync wakeup
Store API Framework-specific Framework-agnostic Proxy

Install

npm install @kronos/warp-core

Quick Start

Low-level signals (SAB-backed)

import { SignalArena, EffectScope } from '@kronos/warp-core';

// Create an arena (shared across all Workers)
const arena = SignalArena.create();
const counter = arena.createSignal(0);

// Set up reactive effects
const scope = new EffectScope(arena);
scope.effect(counter, (value) => {
  console.log('Counter changed:', value);
});

// Write from any thread β€” all effects fire
arena.write(counter, 42);

// Pass to Workers
worker.postMessage({ buffer: arena.buffer }, []);
// In Worker: const arena = SignalArena.from(buffer);

High-level reactive store

import { createStore } from '@kronos/warp-core';

const store = createStore({ count: 0, name: 'KRONOS' });

store.on('count', (newVal, oldVal) => {
  console.log(`count: ${oldVal} β†’ ${newVal}`);
});

store.state.count = 1; // triggers listener

// Batch updates
store.batch((s) => {
  s.count = 10;
  s.name = 'Warp';
}); // listeners fire after all writes

Cross-context sync

import { WorkerSync } from '@kronos/warp-core';

const sync = new WorkerSync({ nodeId: 'main-thread' });

sync.on('state-update', (msg) => {
  console.log('Received update from:', msg.sourceId, msg.payload);
});

sync.send({ type: 'state-update', payload: { count: 42 } });

Devtools

import { SignalArena, installDevtoolsHook, arenaStats, scanSignals } from '@kronos/warp-core';

const arena = SignalArena.create();
installDevtoolsHook(arena);

// Inspect from console:
// globalThis.__WARP_CORE_DEVTOOLS__.arenaStats()
// globalThis.__WARP_CORE_DEVTOOLS__.scanSignals(10)

API

Signal Arena

  • SignalArena.create(byteSize?) β€” Create a new arena (default 64 MB)
  • SignalArena.from(buffer) β€” Reconstruct from SharedArrayBuffer
  • arena.createSignal(initialValue) β€” Allocate a mutable signal
  • arena.createComputed() β€” Allocate a computed node
  • arena.read(offset) β€” Read signal value (atomic)
  • arena.write(offset, value) β€” Write value (CAS-locked, version-bumped)
  • arena.waitForChange(offset, version) β€” Async wait for next write
  • arena.addSubscriber(signal, subscriber) β€” Link subscriber to signal

Effect Scope

  • new EffectScope(arena) β€” Create a scope
  • scope.effect(signalOffset, callback) β€” Register reactive effect
  • scope.stop() β€” Tear down all subscriptions

Reactive Store

  • createStore(initial) β€” Create a Proxy-based store
  • store.on(field, listener) β€” Subscribe to field changes
  • store.onAny(listener) β€” Subscribe to all changes
  • store.batch(updater) β€” Batch multiple writes
  • store.snapshot() β€” Get a shallow copy

Worker Sync

  • new WorkerSync(config) β€” Create a cross-context sync bus
  • sync.on(type, listener) β€” Subscribe to message types
  • sync.send(message) β€” Send to all other nodes
  • sync.close() β€” Close the channel

Devtools

  • inspectSignal(arena, offset) β€” Get signal snapshot
  • arenaStats(arena) β€” Get arena utilization
  • scanSignals(arena, maxCount?) β€” Scan all allocated signals
  • installDevtoolsHook(arena) β€” Expose on globalThis

License

MIT

About

Sub-microsecond reactive runtime β€” SharedArrayBuffer-backed signals with true cross-thread propagation, zero postMessage overhead, and fleet-aware effect scheduling. Designed to supersede Alien Signals. Sorry Stackblitz πŸ‘½

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors