Skip to content
@pyreon/reactivity
core · signals

Delete useMemo, useCallback and every dependency array.

Signals know who reads them, so derived values and effects keep themselves up to date and a write touches only what depends on it. It is the engine under every Pyreon app, with no dependencies, and it runs on its own in Node, Bun, a worker or a script.

bun add @pyreon/reactivity
Documentation
dependencies
noneOne optional peer, used only by the native compiler.
effect propagation
2.0–2.1× Preact SignalsV8, two runs, synthetic, author-run.
dependency arrays
0Dependencies are tracked when a signal is read.
native
signal, computed, effect and batch lower to iOS and AndroidNative targets are experimental.
A signal write reaches only the nodes that read it Schematic signal graph: count.set(2) travels from the count signal to the computed double and on to the two places that read it, a Badge text node and a document.title effect. A separate theme signal and the class it feeds stay grey: they do not depend on count, so they never run. SIGNAL GRAPH · A WRITE REACHES ITS READERS count = 1= 2 theme = 'dark' double = 2= 4 cls skipped <Badge> text: 2text: 4 effect title: 2title: 4 <div class> never re-runs count.set(2) count.set(1) computeds re-track every run
  • 2.1× faster effect propagation than Preact Signals (1,407 vs 2,874 ns, 100 effects)BENCHMARKS.md 2026-11-05 §8, V8, final pass, two runs (2.04–2.13×)
  • 1.95× faster batching of 50 signal writes than Preact Signals (456 vs 888 ns)BENCHMARKS.md 2026-11-05 §8, V8, two runs (1.94–1.95×)
  • 2 of 10,000 row effects re-run when the selection moves, with createSelectorrun on main: .scratch/core/parent/r2.ts prints 2

synthetic · author-run · M3 Max · record of 2026-11-05

Every result, including where we lose →
why teams pick it

Less to write, less to get wrong.

  1. Nothing to list

    A computed or effect subscribes to exactly the signals it read on its last run. When a branch stops reading a signal, the dependency is dropped, so there is no array to keep in sync and no stale closure to chase.

  2. One write, one update

    batch() groups writes and runs each effect once with the final values. A diamond (a feeding two computeds that feed one effect) never shows a half-updated state.

  3. Cheap where lists are big

    A signal with one subscriber keeps it in an inline slot and allocates no Set. createSelector re-runs 2 rows when a selection moves, not 10,000.

  4. Ask why it ran

    Call why() before a write and the console names each signal that changed: [pyreon:why] "first": "Ada" → "Grace" (1 subscriber). inspectSignal and getReactiveTrace go deeper.

the difference

The same cart, with and without dependency arrays.

React

Three dependency arrays to keep right, and the whole function runs again on every click.

import { useState, useMemo, useEffect, useCallback } from 'react'

export function Cart({ price }: { price: number }) {
  const [qty, setQty] = useState(1)
  const total = useMemo(() => price * qty, [price, qty])
  const add = useCallback(() => setQty((n) => n + 1), [])

  useEffect(() => {
    document.title = `Total: ${total}`
  }, [total])

  return (
    <button onClick={add}>
      {qty} × {price} = {total}
    </button>
  )
}
Pyreon

No arrays. The function runs once; a click updates two text nodes and the title.

import { signal, computed, effect } from '@pyreon/reactivity'

export function Cart(props: { price: number }) {
  const qty = signal(1)
  const total = computed(() => props.price * qty())

  effect(() => {
    document.title = `Total: ${total()}`
  })

  return (
    <button onClick={() => qty.update((n) => n + 1)}>
      {qty()} × {props.price} = {total()}
    </button>
  )
}
the engine underneath

What turns signals into pixels.

@pyreon/core
components

JSX, components, context, For, Show and lifecycle.

@pyreon/compiler
compiler

Decides at build time which expressions are live.

@pyreon/runtime-dom
browser

Fine-grained DOM updates and hydration.

@pyreon/runtime-server
server

Streaming SSR to strings and streams.

@pyreon/sized-map
internals

A bounded cache used across the engine.

coming from

Coming from React useState, React useMemo or React useEffect?

State you can read right after you write it

React useState
const [count, setCount] = useState(0)

function addTwo() {
  setCount(count + 1)
  setCount(count + 1) // still the old count: adds 1, not 2
}
Pyreon

count() reads, count.set(v) writes, count.update(fn) derives. Calling count(5) only reads, so writes are always .set.

const count = signal(0)

function addTwo() {
  count.set(count() + 1)
  count.set(count() + 1) // reads the new value: adds 2
}

Derived values without a dependency list

React useMemo
const total = useMemo(() => price * qty, [price, qty])
Pyreon

A computed is lazy and cached: it recomputes only when read after a dependency changed. If it returns a new object each time, pass { equals } so readers skip identical results.

const total = computed(() => price() * qty())

Side effects that re-run on their own

React useEffect
useEffect(() => {
  const id = setInterval(tick, delay)
  return () => clearInterval(id)
}, [delay])
Pyreon

The effect re-runs when delay changes, cleaning up first. Effects run synchronously after a write (or once at the end of a batch), and one created inside a component is disposed with it.

effect(() => {
  const id = setInterval(tick, delay())
  return () => clearInterval(id)
})
try it

Write signals, count the runs.

Two signals, one computed, one effect. Batching groups writes so the effect runs once.

  • price = signal(100)0
  • qty = signal(2)0
  • total = computed · 2001
  • effect runs1

Numbers count writes and runs. They are read from the signals themselves.

benchmarks

Fastest where an update spends its time: propagation.

Pyreon wins the work a real update runs through: effect propagation, batching and the computed diamond. It loses raw signal creation (4.8×), deep unobserved chains (1.42×) and wide fan-out (3–4%), and those rows stay in the table.

vs Preact Signals and Solid · V8 (Node 26), Pyreon bundled · plus the 10-framework row boardPyreonrival · lower is better
  • effect propagation (100)
    1,407 ns
    2,874 ns
    win2.04–2.13× vs Preact
  • batch 50 signals
    456 ns
    888 ns
    win1.94–1.95× vs Preact
  • computed diamond (100 updates)
    4,424 ns
    5,761 ns
    win1.30–1.31× vs Preact
  • wide fan-out (1 → 100 effects)
    1,651 ns
    1,602 ns
    lossPreact 1.03–1.04× ahead
  • deep chain (depth 50)
    107,237 ns
    75,639 ns
    lossPreact 1.42–1.43× ahead
  • signal create + read + write
    63 ns
    13 ns
    lossPreact 4.8× ahead
  • create 10,000 rows (vs React 19)
    72.64 ms
    192.01 ms
    split2.6× vs React 19; vs the fastest rivals a split: tie in one run, 1.02× in the other
  • clear 1,000 rows
    130 µs
    145 µs
    win1.11–1.12× vs Vue 3.6 Vapor, the fastest rival
Apple M3 Max · record of 2026-11-05 · final pass, two runs · author-run, syntheticFull method, every loss →
what's included

Every reactive primitive you reach for.

  • signal with set, update, peek and trigger for values mutated in place
  • computed lazy and cached, with optional equals
  • linkednext release a writable value that resets when its source changes
  • effect and onCleanup, plus renderEffect for the cheapest DOM bindings
  • batch and nextTick: nested batches flush once, at the outermost exit
  • watch for an explicit source and a (next, prev) callback
  • createSelector for O(1) selection in long lists
  • createStore and reconcile for deep reactive objects and patching them from API responses
  • createResource for async data with loading, error and stale-response handling
  • why, inspectSignal and getReactiveTrace to see what changed and what ran
recipes

Things to build with it.

Selection in a 10,000-row list

A plain selected() === id check in every row re-runs all 10,000 rows on each click. createSelector keeps a bucket per value and notifies only the row that lost the selection and the one that gained it.

import { signal, effect, createSelector } from '@pyreon/reactivity'

const selected = signal(-1)
const isSelected = createSelector(() => selected())

let runs = 0
for (let id = 0; id < 10_000; id++) {
  effect(() => {
    isSelected(id) // in a real row: class={isSelected(id) ? 'row on' : 'row'}
    runs++
  })
}

runs = 0
selected.set(42)
selected.set(7)
console.log(runs) // 3: one row for the first pick, then two for the move
Search that never shows a stale answer

createResource refetches when its source changes and ignores any response that arrives after a newer request started, so a slow reply to "p" can't overwrite the answer to "py".

import { signal, createResource } from '@pyreon/reactivity'

const query = signal('')
const results = createResource(
  () => query(),
  (q) => fetch(`/api/search?q=${encodeURIComponent(q)}`).then((r) => r.json()),
)

query.set('p')  // slow request
query.set('py') // fast request
// results.data() ends up holding the answer to 'py', whichever reply lands last
// results.loading() and results.error() are signals too
next release
A choice that resets when its options change

linked() follows a source like a computed but can be overwritten like a signal. Keep the user's pick while it is still offered; fall back to the first option when it is not.

import { signal, linked } from '@pyreon/reactivity'

const sizes = signal(['S', 'M', 'L'])
const size = linked(sizes, (opts, prev): string =>
  prev && opts.includes(prev.value) ? prev.value : (opts[0] ?? ''),
)

size.set('L')
console.log(size()) // 'L'
sizes.set(['M', 'L', 'XL'])
console.log(size()) // 'L' (still offered, kept)
sizes.set(['XS', 'S'])
console.log(size()) // 'XS' (gone, reset)
api

Grouped the way you use them.

Every export has a reference page with its signature, an example and the mistakes people make with it.

core · 9
  • signal
  • computed
  • effect
  • renderEffect
  • batch
  • nextTick
  • untrack
  • watch
  • cell
structures · 8
  • createStore
  • reconcile
  • shallowReactive
  • markRaw
  • isStore
  • createResource
  • createSelector
  • wrapSignal
lifetimes · 4
  • effectScope
  • onCleanup
  • onScopeDispose
  • getCurrentScope
debugging · 7
  • why
  • inspectSignal
  • onSignalUpdate
  • getReactiveTrace
  • getReactiveGraph
  • describeReactiveGraph
  • setErrorHandler
next release · 1
  • linked
good to know

Good to know before you start.

Mutating in place needs trigger()

Signals compare with Object.is, so set(sameObject) does nothing. Update immutably, or mutate and call trigger().

Read inside a tracking scope

A signal read in a plain function body subscribes nothing. Read it in an effect, a computed or JSX.

A new object every time means a notify every time

A computed that returns a fresh object or array notifies on each recompute. Pass equals when readers should skip identical results.

Cheap to update, not the cheapest to create

Creating a signal costs about 5× what Preact Signals does (63 vs 13 ns on V8). Create them once, not inside hot loops.

questions

What people ask first.

Can I use it without the rest of Pyreon?

Yes. It has no dependencies and no DOM code: bun add @pyreon/reactivity and use it in Node, Bun, a worker or a CLI. Pyreon's components, router, forms, queries and stores all build on it.

Are effects synchronous?

Yes. A write runs the effects that depend on it before set() returns, unless you are inside batch(), which runs them once at the end. await nextTick() waits for the DOM after a write.

How does it compare with Preact Signals and Solid?

Same model, measured: about 2.1× Preact on effect propagation, 1.95× on batching and 1.3× on a computed diamond (V8, two runs). It loses signal creation (4.8×), deep unobserved chains (1.42×) and wide fan-out by 1.03×. Solid is behind on every row except creation.

Why count() and not count.value?

A signal is a function, so reading it is a call and passing it around passes the live value. There are no proxies unless you ask for one with createStore.

Does it work in the iOS and Android builds?

Yes, on the experimental native targets: signal and computed compile to SwiftUI and Compose state through PMTC, effect re-runs when what it read changes, and batch lowers too. linked(), coming in the next release, has no native lowering yet, and the compiler warns by name when it meets one.

Your components stop re-rendering. You stop wondering why they did.

bun add @pyreon/reactivity
Read the reactivity guide