Performance changes
Each section lists how a version changed the speed or the memory of VideState, measured with the benchmark in tests/bench/ in Roblox Studio, on one machine, before and after the change. A single run varies by about a quarter, so compare the size of a change, not the exact numbers. The numbers of the current version, and what they mean for your game, are on the Performance page.
0.9.0
Creating handlers
A handler made inside a Vide scope is destroyed with it, which needs a check for a scope on every new. Vide has no way to ask for one, and the first check caught the error Vide raises outside a scope, which cost about 3 µs per handler made outside a scope. The check now tells the two apart without an error. Measured with PlainSources.spec.luau, two runs of each, the fastest round:
| What | Before | After |
|---|---|---|
| Create a handler of a static rule | 8.6–10.3 µs | 3.5–6.9 µs |
| Create a handler of a static rule, shared frozen states | 6.3–8.3 µs | 2.7–4.2 µs |
| Create a handler of a dynamic rule | 12.3–14.3 µs | 8.7–9.3 µs |
Frames of animate
After the first frame of a transition, animate writes only the fields that move, and one moving field is written without a Vide.batch. Measured with Running.spec.luau and the manual clock, three alternating runs of each, the fastest round:
| What | Before | After |
|---|---|---|
A frame of 1,000 handlers, one animate each, one of four fields moving | 679–787 µs | 480–484 µs |
A frame of 1,000 handlers, one animate each, both of two fields moving | 763–821 µs | 769–821 µs |
0.8.0
Handlers
A handler became much lighter, and a handler that only binds its sources and changes state now costs close to plain Vide sources.
| What | Before | After |
|---|---|---|
setState with nothing connected | 18–26 µs | 2.2–2.4 µs |
setState with one animate | 24–35 µs | 14–20 µs |
rule.new with 4 states of 2 fields | 35–45 µs | ≈15 µs |
| A handler with 4 states of 2 fields, in memory | ≈21.4 KB | 5.7–6.5 KB |
A handler with one animate connection, in memory | ≈23 KB | ≈10 KB |
A running transition with one animate connection, in memory | 8.6–9.0 KB | ≈5.3 KB |
| Changing the state of a static handler with bound fields | ≈7.7 µs | ≈0.9 µs |
| Changing the state of a dynamic handler with bound fields | ≈29 µs | ≈3 µs |
- A handler makes its features, such as its events, pause, transitions, and sequences, the first time one is used, and its functions the first time they are read. The first connection of a kind on a handler now includes the feature it needs, so it costs a little more than a later one.
- Checking a Vide source reads it once, without a reactive scope. Before, every check built and destroyed a Vide effect.
setStatereads the values of the state it leaves only when anonChangelistener or a transition connection receives them.
Schema checks
VideState checks values with its own schema core instead of Typed. A check that passes allocates nothing but the table of values it returns, and the error tables are made only when it fails. The error messages are the same, word for word. These were measured in two runs of each version in one session, and a run varies a lot, so the ranges are wide.
| What | Before | After |
|---|---|---|
| Changing the state of a dynamic handler with bound fields | 7.8–15 µs | 1.9–3.4 µs |
| Creating a dynamic handler with 2 fields | 16–25 µs | 5–12 µs |
rule.new with 4 states of 20 fields | 108–115 µs | 76–87 µs |
setState with nothing connected | 4.9–7.1 µs | 1.9–2.6 µs |
setState with one onChange | 7.3–11.4 µs | 2.5–6.6 µs |
| A handler with 4 states of 2 fields, in memory | 5.7–6.5 KB | ≈3.5 KB |
| A rule with 2 fields, in memory | ≈4.0 KB | ≈4.6 KB |
A rule holds a little more, because each of its schemas keeps the lists that its check walks. A rule is shared by all of its handlers, so this is paid once per rule.
Shared states
A static rule checks a states table that is frozen all the way down once, and the handlers made from it share the check and the copy of the values.
| What | Before | After |
|---|---|---|
| Creating a static handler from a shared frozen states table | 6.4–9.8 µs | 3.4–4.8 µs |
Starting a transition
Starting a transition makes far less garbage. A run is one record that the shared loop steps with shared functions, instead of eight closures and three tables, and what is the same for every run of a connection is kept on the connection. The plan of a transition, which fields move and how, is one flat array, and a static rule keeps the plan of each pair of its states, so its handlers stop working it out again. setState reads the state it leaves without checking it again, and a dynamic rule checks the state it enters field by field.
| What | Before | After |
|---|---|---|
A running transition with one animate connection, in memory | ≈4.3 KB | ≈2.6 KB |
| A handler with 4 states of 2 fields, in memory | ≈3.4 KB | ≈3.7 KB |
| Starting a transition on 1,000 handlers of a dynamic rule | 11.9–12.3 ms | 10.5–10.6 ms |
| Building the tween of a static rule's states, with its kept plan | ≈1.8 µs | ≈0.4 µs |
The time of one setState with a connection is hard to measure on its own, because the collector runs during it, so the start is measured on 1,000 handlers after the collector has settled.
Timing under load
A transition takes its own duration when the frames are slow. Before, the shared loop left out the time it spent stepping, so with thousands of transitions at once, or with slow onTransition callbacks, every transition ran slower than real time.
| What | Before | After |
|---|---|---|
| A 0.4 second transition whose callback takes 25 ms a frame | 2.2 s | 0.46 s |
| Progress of a 1 second transition after 0.8 s, with 5,000 handlers running | ≈27% | 80% |
Frames
A frame of the shared loop became about 40% cheaper in all. The last step blends number fields inline instead of calling a blend function, and animate writes its sources from the tween's positions directly. With one animate connection on 1,000 handlers, a frame went from ≈883 µs to ≈797 µs in two runs of each. With three connections the runs varied too much to tell.
Before that, a frame had become about 35 to 40% cheaper. With 1,000 handlers in a transition, one step took 1.4–1.5 ms with one animate connection on each handler and 4.1–5.7 ms with three, and takes ≈0.8 ms and ≈2.4 ms now.
The comparison with hand-written code measured each change on its own:
| Change | Frame at 1,000 | Frame at 5,000 | Frame at 10,000 |
|---|---|---|---|
| Before | ≈1.5 ms | ≈27 ms | ≈57 ms |
animate and progress read each frame without building a table | ≈1.03 ms | ≈22 ms | ≈46 ms |
| One protected call per frame instead of one per transition | ≈1.00 ms | ≈21.4 ms | ≈46 ms |
| The list of transitions is compacted in place | ≈0.98 ms | 16.5–19 ms | ≈42 ms |
| The eased progress is reused between transitions with the same easing | no change with a linear easing, ≈19% less at 1,000 with a shared spring | within noise | within noise |
| Settings that are plain values are read once per transition | ≈0.89 ms | ≈16.7 ms | ≈38 ms |
Each row includes the ones above it, and each was measured in two runs on the same machine, so differences of a few percent are noise. Before these changes the hand-written side also looked slower at 10,000 components (≈14–16 ms), because the collector was freeing the tables that VideState built on every frame while the hand-written side ran.
0.4.0
VideState tweens values itself instead of using Ripple. The shared frame step blends every field and the alpha with one eased progress and builds no signals, which made each connection 20 to 30% faster, with the same values.
0.2.0
Every running transition is stepped by one shared loop, which runs only while a transition is running, instead of a loop for each transition.