Skip to content

feat: dependency lists for reactive ui functions - #724

Draft
makspll wants to merge 6 commits into
agent/reactive-ui-eachfrom
agent/reactive-ui-script-props
Draft

makspll wants to merge 6 commits into
agent/reactive-ui-eachfrom
agent/reactive-ui-script-props

Conversation

@makspll

@makspll makspll commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Functions of the reactive ui can take dependencies: values handed back to them as their first arguments, instead of captured.

local double = ui.computed(function(n) return n:get() * 2 end, { n })     -- also effect, show, list
ui.node({ on_click = { function(selected, name) selected:set(name) end, selected, name } })
ui.element(Slot, slot, { name, entity, is_selected })                      -- slot(name, entity, is_selected)
  • computed(f, deps), effect(f, deps), show(f, deps), list(items, f, deps)
  • a handler or bound property is a list starting with the function: { f, a, b }
  • element(Def, f, deps, key) renders a component with f(deps..) instead of a props table

Why: closures of Rune can only capture numbers and strings when handed to Rust (rune_function_to_script), not signals or entities, so without this a Rune component can only share state through the per-script state() store, one instance per component. In Lua it is optional, captures work as before.

This replaces the Lua only "function instead of props" of the first version of this PR (that form still works in Lua, it is element(Def, f) without dependencies).

Cost, same binary, 3 rounds, the Closures ui with every function taking dependencies instead of capturing:

bench captures dependencies
inventory mount or unmount 200 1.79 ms 2.44 ms (+37%)
inventory search 1.49 ms 1.99 ms (+33%)
inventory select 23.0 µs 24.1 µs (+5%)

The cost is the references (signals, entities) converted on every call, about ten per slot when mounting. A first version with a ui.callback(f, deps) function was +55%, each one being its own call into Rust, hence the list form. So: capture where the language can, and use row templates for large lists, which need neither.

@makspll
makspll added this pull request to stack #718 November 13, 2026 10:27
@semanticdiff-com

semanticdiff-com Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

ProjectBevy Scripting
Branchagent/reactive-ui-script-props
Testbedlinux-gha

⚠️ WARNING: Truncated view!

The full continuous benchmarking report exceeds the maximum length allowed on this platform.

⚠️ WARNING: No Threshold found!

Without a Threshold, no Alerts will ever be generated.

🐰 View full continuous benchmarking report in Bencher

…rops

# Conflicts:
#	assets/benchmarks/reactive_ui/closures.lua
#	assets/benchmarks/reactive_ui/paths.lua
#	assets/tests/reactive_ui/inventory/inventory.lua
#	crates/bevy_mod_scripting_reactive_ui/src/lib.rs
@makspll makspll changed the title perf: reactive ui component props can stay in the script feat: dependency lists for reactive ui functions Nov 13, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant