Luau-signals - luau port of alien-signals

luau-signals

Luau Port of alien-signals :alien_monster: the lightest signal library

GitHub Repository Get on Wally Get on Pesde Documentation GitHub Releases Roblox OSS Server Changelog My Works

About

luau-signals is a faithful Luau port of alien-signals, a push-pull reactive signals library whose core algorithm has been adopted by Vue 3.6. It brings the same signal / computed / effect / effectScope primitives to Luau 🦭 and Roblox, with the same lazy, glitch-free semantics: signals hold state, computed values are derived lazily, effects react to changes, and scopes let you dispose whole component trees at once.

The port preserves the upstream constraints that make alien-signals fast. Writes push flags through the graph while reads pull fresh values only when needed, so an unobserved computed chain is never touched. The hot path uses linked lists and plain arrays only — no Set, no Map, no dynamic fields — and propagate, checkDirty, and shallowPropagate are iterative rather than recursive. Each Link is seven flat fields with no hidden allocation.

What is specific to Luau is mostly adaptation. Signals, computed values, and effects are callable tables — the node is the API — so no closure or wrapper is allocated per node. Node kinds are identified by metatable identity instead of 'getter' in node checks, which cannot be ported literally because a nil-valued field does not exist in Luau; this also makes signal(nil) unambiguous. All flag operations go through bit32 (Luau has no native &, |, ~ for numbers), with masks precomputed and bit32.btest used for “any of these bits set”. Every finally block from the original is reproduced with pcall plus a re-error, including state restoration on thrown errors, and the linked-list stack is replaced with a plain array plus a depth counter for cheaper push/pop and safe reentrancy.

Getting Started

Please follow the documentation here!

Benchmarks

Currently, Vide is the most popular and frequently chosen reactivity library for Luau, thanks to its speed and an API largely derived from Solid.js - which is why it was selected for comparison with luau-signals. Furthermore, unlike Fusion, Vide is currently being actively maintained and updated.

Comparing with Vide
Scenario signals vide Winner Rupture
batch: 10 writes, batched 1.86 µs 1.89 µs ≈ equal ~1.0×
batch: 10 writes, no batch 10.2 µs 12.0 µs :green_circle: signals 1.17×
derive: 1 src → 50 derives → 1 effect 12.4 µs 17.3 µs :green_circle: signals 1.39×
derive: chain depth 10 2.36 µs 2.53 µs :green_circle: signals 1.07×
derive: chain depth 10 → effect 2.41 µs 2.60 µs :green_circle: signals 1.08×
derive: chain depth 40 7.79 µs 9.50 µs :green_circle: signals 1.22×
derive: cutoff (value unchanged) 529 ns 308 ns :red_circle: vide 1.72×*
derive: diamond → effect 1.17 µs 1.11 µs ≈ equal ~1.0×
derive: unobserved (lazy vs eager) 137 ns 2.44 µs :green_circle: signals 17.83×
derive: write + read (depth 1) 377 ns 371 ns ≈ equal ~1.0×
effect: create + dispose 1.14 µs 1.11 µs ≈ equal ~1.0×
effect: dynamic deps (branch toggle) 681 ns 421 ns :red_circle: vide 1.62×*
effect: rerun with cleanup 465 ns 453 ns ≈ equal ~1.0×
graph: 20 src + 20 derive 18.8 µs 21.2 µs :green_circle: signals 1.12×
mixed: 30 src, 60 derive, 15 effects 2.68 µs 9.90 µs :green_circle: signals 3.69×
source: create 110 ns 106 ns ≈ equal ~1.0×
source: read (untracked) 37 ns 56 ns :green_circle: signals 1.52×
source: write, no subscribers 46 ns 81 ns :green_circle: signals 1.76×
source: write, same value 37 ns 39 ns ≈ equal ~1.0×
write → 1 effect 419 ns 317 ns :red_circle: vide 1.32×*
write → 10 effects 2.21 µs 2.62 µs :green_circle: signals 1.18×
write → 100 effects 18.9 µs 25.2 µs :green_circle: signals 1.34×

* - Scenarios where Vide excels - essentially its “natural habitat” - are those involving a single action (e.g. write operation resulting in one effect) or situations where nothing changes following an update. In such cases, its “eager” update model incurs lower computational overhead. For larger-scale tasks, luau-signals is a better choice.

Comparing with Fluid (fork of Vide)
Scenario signals fluid Winner Rupture
batch: 10 writes, batched 2.07 µs 54.92 µs :green_circle: signals 26.53×
batch: 10 writes, no batch 12.09 µs 56.54 µs :green_circle: signals 4.68×
derive: 1 src → 50 derives → 1 effect 13.79 µs 636.90 µs :green_circle: signals 46.19×
derive: chain depth 10 2.58 µs 10.72 µs :green_circle: signals 4.15×
derive: chain depth 10 → effect 2.65 µs 11.46 µs :green_circle: signals 4.32×
derive: chain depth 40 8.93 µs 39.75 µs :green_circle: signals 4.45×
derive: cutoff (value unchanged) 627.8 ns 1.75 µs :green_circle: signals 2.79×
derive: diamond → effect 1.21 µs 4.81 µs :green_circle: signals 3.98×
derive: unobserved (lazy vs eager) 145.0 ns 386.7 ns :green_circle: signals 2.67×
derive: write + read (depth 1) 424.0 ns 1.42 µs :green_circle: signals 3.35×
effect: create + dispose 1.25 µs 2.84 µs :green_circle: signals 2.27×
effect: dynamic deps (branch toggle) 774.7 ns 2.19 µs :green_circle: signals 2.83×
effect: rerun with cleanup 526.5 ns 1.91 µs :green_circle: signals 3.63×
graph: 20 src + 20 derive 23.13 µs 45.53 µs :green_circle: signals 1.97×
mixed: 30 src, 60 derive, 15 effects 3.09 µs 10.66 µs :green_circle: signals 3.45×
source: create 121.4 ns 254.3 ns :green_circle: signals 2.10×
source: read (untracked) 41.8 ns 82.4 ns :green_circle: signals 1.97×
source: write, no subscribers 51.8 ns 166.4 ns :green_circle: signals 3.21×
source: write, same value (no-op) 41.6 ns 81.1 ns :green_circle: signals 1.95×
write → 1 effect 477.7 ns 1.51 µs :green_circle: signals 3.16×
write → 10 effects 2.36 µs 14.08 µs :green_circle: signals 5.97×
write → 100 effects 20.16 µs 136.33 µs :green_circle: signals 6.76×
Comparing with Flux (@kohltastrophe)
Scenario signals flux Winner Rupture
batch: 10 writes, batched 2.10 µs 2.22 µs :green_circle: signals 1.06×
batch: 10 writes, no batch 11.38 µs 12.38 µs :green_circle: signals 1.09×
derive: 1 src → 50 derives → 1 effect 13.59 µs 15.03 µs :green_circle: signals 1.11×
derive: chain depth 10 2.30 µs 3.01 µs :green_circle: signals 1.31×
derive: chain depth 10 → effect 2.43 µs 2.85 µs :green_circle: signals 1.17×
derive: chain depth 40 7.78 µs 8.52 µs :green_circle: signals 1.10×
derive: cutoff (value unchanged) 602.9 ns 678.0 ns :green_circle: signals 1.12×
derive: diamond → effect 1.12 µs 1.34 µs :green_circle: signals 1.20×
derive: unobserved (lazy vs eager) 136.9 ns 135.1 ns ≈ equal ~1.0×
derive: write + read (depth 1) 366.4 ns 448.0 ns :green_circle: signals 1.22×
effect: create + dispose 1.15 µs 1.37 µs :green_circle: signals 1.19×
effect: dynamic deps (branch toggle) 728.8 ns 820.4 ns :green_circle: signals 1.13×
effect: rerun with cleanup 476.2 ns 536.8 ns :green_circle: signals 1.13×
graph: 20 src + 20 derive 22.84 µs 22.52 µs ≈ equal ~1.0×
mixed: 30 src, 60 derive, 15 effects 2.97 µs 3.09 µs ≈ equal ~1.0×
source: create 116.8 ns 127.7 ns :green_circle: signals 1.09×
source: read (untracked) 36.9 ns 40.9 ns :green_circle: signals 1.11×
source: write, no subscribers 48.0 ns 53.8 ns :green_circle: signals 1.12×
source: write, same value (no-op) 39.1 ns 41.8 ns :green_circle: signals 1.07×
write → 1 effect 420.0 ns 499.1 ns :green_circle: signals 1.19×
write → 10 effects 2.20 µs 2.43 µs :green_circle: signals 1.10×
write → 100 effects 18.57 µs 20.69 µs :green_circle: signals 1.11×

flux is close to signals — within 1.1–1.3× on almost every scenario, unlike fluid (2–46× slower). The one clear gap is derive: chain depth 10 at 1.31×; unobserved, graph, and mixed are within noise. This suggests flux also uses a lazy push-pull model with similar overhead; the difference is likely in constant factors (getmetatable vs internal tags, closure handling, queue flush strategy) rather than architecture.

Code Sample

const luau_signals = require './luau-signals'
const signal, computed, effect, effectScope, startBatch, endBatch =
    luau_signals.signal, luau_signals.computed, luau_signals.effect, luau_signals.effectScope, luau_signals.startBatch, luau_signals.endBatch

const price, qty = signal(100), signal(2)
const total = computed(function()
    return price() * qty()
end)

-- effectScope — groups effects for collective disposal
const dispose = effectScope(function()
    -- effect — reacts to changes
    effect(function()
        print(`Total: { total() }`)
    end)
end) -- Output: `Total: 200`

price(150) -- Output: `Total: 300`

-- batch — multiple changes → a single effect restart
startBatch()
price(200)
qty(5)
endBatch() -- Output: `Total: 1000`

dispose() -- Unsubscribing from the entire scope
price(999) -- Nothing is being output

Attribution

The core algorithm is by Johnson Chu (alien-signals, MIT).

luau-signals is licensed under MIT License

2 Likes

fixed badges & logo (ty roblox for that)

so much bloat
Just iterate a function array instead

--define
local callback = {}

--connect
callback[1]=function()end--or use table.insert

--call
for i,v in callback do v() end

The goal isn’t just to make it work; the code should also resemble the original. Also, I’m not entirely sure what you meant by “bloat.”

1 Like

its yarik bro anything beyond absolute necessity is bloat for him

4 Likes

BASED!?

Literally basic human logic, bro.

Bloat = bad.

Also, have some basic human empathy for players who have to run that bloat.

Who pays for it?

  • Players with weaker hardware.
  • Players on mobile devices.
  • Players with limited memory.
  • Players with weaker CPUs and GPUs.
  • Players who simply want their hardware used for the actual game.

You’re basically imposing unnecessary resource consumption on everyone who has to run your software.

Optimization isn’t just developer vanity. It’s also consideration for the people running your software.

Have you considered that your unnecessary abstraction is consuming someone’s last 200 MB of RAM?

Have you considered that your framework is competing with the actual game for CPU time?

Have you considered that not everyone has a NASA computer to compensate for your architectural decisions?

TNLO Human Empathy Department:

“Have some basic human empathy. Your players’ hardware isn’t an infinite resource pool.”

Let’s put it this way - where exactly did you see “bloat” in my work? I’m genuinely curious to hear your perspective on this.

1 Like

Another alien signals port! I’d love to see how this compares with my benchmark :eyes:

I’d recommend looking into some of the recent advancements with SolidJS, they’re doing really cool stuff.

1 Like

Yeah, I see that becnhmark, I can help with the adapter via a PR, if needed :seal:

By the way, the Flux library’s API came as a very pleasant surprise - I can help with optimizations for the upcoming 0.5.0/1.0.0 releases.

1 Like

I’ll take all the help I can get, feel free to open an issue or a PR. Also contributors to Flux will also be listed as contributors in Kohl’s Admin since it’s built with it. :slight_smile:

3 Likes

I’m glad that UI libraries are back in fashion; it’s reached the point where specific libraries are being created for specific, individual use cases. This is great to see - for instance, luau-signals wasn’t even originally planned; it came into existence because I’m working on a Luau port of Vue 3.6 (which utilizes system.ts from alien-signals). I decided it would be a good idea to release it separately as a “compact implementation” derived from that upcoming library (i.e., alien-signals).

I’ll be glad to become a part of your wonderful library, so I’ll get around to that soon :heart_with_ribbon:

2 Likes

Looks good sir, very well written and well documented.

2 Likes