Repository navigation
perf: push animated values from the shared slot block - #20
Merged
riteshshukla04 merged 5 commits intoNov 4, 2026
Merged
Conversation
setValues takes a number[], so every animated frame builds an array that Nitro converts into a std::vector before the renderer swaps it in. A view can now bind the Float64 block behind a TgfxSlots values buffer once (bindValues) and copy it natively on each pushValues(), so only the call crosses JSI per frame. The renderer copies under the same lock as setValues, and clearScene drops the binding. Each platform view keeps the bound ArrayBuffer until the next bind, and the slots object now shares its value storage with the buffers it hands out, so a bound canvas can outlive it.
|
@SectionTN is attempting to deploy a commit to the Margelo Team on Vercel. A member of the Team first needs to authorize it. |
The driver already writes every animated value into the mirror block for the next commit's snapshot. It now binds that block to the view once per mapper and calls pushValues() each frame instead of building a slot array for setValues. A view without pushValues, or a canvas without a mirror, still gets the array. On a Pixel 9a emulator (debug build) a push of 256 values drops from 44 us to 7 us, and 4096 values from about 665 us to 87 us. A harness case covers a value set that changes while the canvas animates.
A Scene attached to a canvas runs the same mapper as the driver but still sent setValues(slots) to every target each frame. A target that has pushValues now binds the mirror once and copies it natively, while an offscreen surface or an older binary keeps getting the array, which the mapper now fills only when some target reads it. With 1024 slots on a Pixel 9a emulator (debug build) a frame for one canvas drops from about 166 us to 33 us, and a second canvas adds about 1.5 us instead of another 124 us marshal.
On iOS a canvas hidden with display: none is unmounted and its view is recycled, which clears the binding. When the canvas shows again it keeps the same view, so the mapper still counts it as bound and every push is dropped: the animation freezes until the value set changes. setValues had no such state to lose. pushValues now returns false while nothing is bound, and the driver and the Scene mapper bind again and retry. bindValues also rejects a JS-owned buffer, which would leave the renderer reading memory its runtime frees.
bindValues and pushValues serve the animation driver and the Scene mapper and need a native-owned slot block that callers cannot create, so they are @internal and drop out of the API reference. Comments that named setValues as the per-frame push now say value push, and the roadmap entry for sending values through a shared ArrayBuffer is marked done.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Reanimated driver sent its animated values with
setValues(number[])on every frame, so each frame built a JS array that Nitro converted into astd::vectorbefore the renderer swapped it in (the ROADMAP item about sending values through a shared ArrayBuffer). The driver already writes those values into the mirror block it keeps for the next commit, so the view now binds that block once and copies it natively onpushValues(). A Scene's mapper does the same for canvas targets. Offscreen surfaces and older native binaries keep the array.Per push on a Pixel 9a emulator, median of 3 runs, in microseconds:
A Scene attached to two canvases gains more, since its second target costs one native copy where main marshals the array again: 760.6 to 121.8 us per frame for 4096 slots in a release build.
Risk: the binding is native state that
setValuesnever had. A recycled view drops it (on iOS that happens to a canvas hidden withdisplay: none), sopushValuesreturns false and the mapper binds again. One harness case covers that, and another covers a value set that changes while the canvas animates.Tested with bun test, tsc, eslint, prettier and clang-format, and with the imperative, imperativeScene, workletScene, rendering and viewport harness suites on a Pixel 9a emulator and an iOS 27.2 simulator.