ludic.ui: a screen's nodes and envs are pooled and used again - two generations a screen, reset in place, their own lists emptied not replaced; a tree is good until its screen is built twice more (benchmark 256 -> 110 KB a frame)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-27 23:33:48 +03:00
parent 83200a453b
commit d1c9359e96
19 changed files with 307 additions and 83 deletions

View file

@ -1,14 +1,14 @@
# build_more.ludic - <let name="{value}"/> names a value for the siblings after it, and
# <provide name="{value}"> gives it to everything inside, components included (React's context)
function bd_let(ui_st: mut UiState, k: UiTpl, e: UiEnv) -> UiEnv {
let le = env_new(e)
let le = env_new(ui_st, e)
for i in 0 .. len(k.keys) { env_bind(le, k.keys[i], ui_eval(ui_st, k.vals[i], e)) }
return le
}
function bd_provide(ui_st: mut UiState, k: UiTpl, e: UiEnv, key: string, out: []UiNode) -> void {
let cx = env_new(e.ctx)
let cx = env_new(ui_st, e.ctx)
for i in 0 .. len(k.keys) { env_bind(cx, k.keys[i], ui_eval(ui_st, k.vals[i], e)) }
let pe = env_new(e)
let pe = env_new(ui_st, e)
pe.ctx = cx
bd_kids(ui_st, k.kids, pe, key, out)
}
@ -18,12 +18,11 @@ function bd_group(ui_st: mut UiState, k: UiTpl, e: UiEnv, key: string, out: []Ui
bd_kids(ui_st, k.kids, e, key, out)
return
}
let t = new UiNode
let t = nd_take(ui_st)
t.kind = UI_TEXT
t.key = key
t.text = ui_tr(ui_st, ui_eval_text(ui_st, k.text, e))
t.env = e
t.children = new []UiNode
push(out, t)
}
# text inside text - <p>Hi <b>there</b></p>, <h3><slot/></h3> - reads as one line of it
@ -37,5 +36,5 @@ function el_inline(n: UiNode) -> void {
s = s + c.text
}
n.text = s
n.children = new []UiNode
List.clear(n.children)
}