ludic.ui: a new component instance's first build is declared - a first show mid-play is not a frame's keep
Master's windowed fog profile failed the fence at walk t 35 s: +512 B from value_new / value_put / value_slot / value_lists under bd_class and cmp_keycap_model - a KeyCap first shown mid-walk. It is a first build, bounded, not a per-show leak: an unmounted instance goes to in_free and the next show of its class reuses it (in_reuse, `renew`), its props and model objects kept and filled in place. Only a NEW instance makes them - bounded by how many of that class are up at once, and the ones unmounted less than two builds ago. in_reuse already declared the record; the props and model objects and their first fill, made afterwards in bd_class, were not. They are now: in_reuse marks a new record `fresh`, and bd_class's first fill of it goes through bd_first_fill (@alloc_ok) - a reused instance's fill stays judged, so a real per-show leak would still fail. Golden ui_first_show: a component first shown at frame 700, once the fence is judging, then hidden and shown twice more: bad 0 (the toolchain before this fails frame 701: +464 B value_new from value_slot under cmp_cell_model, value_put grow - the profile's failure). The 37 ui examples pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
b9f9cb8495
commit
2958539514
10 changed files with 67 additions and 10 deletions
|
|
@ -5,17 +5,8 @@ function bd_class(ui_st: mut UiState, k: UiTpl, e: UiEnv, key: string, out: []Ui
|
|||
let cls = k.cls
|
||||
uc_load(ui_st, cls)
|
||||
let it = in_get(ui_st, key, cls)
|
||||
if it.props == null { it.props = Value.object() }
|
||||
let props = it.props
|
||||
Value.clear(props)
|
||||
for i in 0 .. len(k.keys) {
|
||||
let a = k.keys[i]
|
||||
if a != "class" and a != "style" and a != "id" { Value.put(props, a, ui_eval(ui_st, k.vals[i], e)) }
|
||||
}
|
||||
cls.props(it.ptr, props)
|
||||
let ce = env_new(ui_st, null)
|
||||
if it.model == null { it.model = Value.object() }
|
||||
ce.model = cls.model(it.ptr, it.model)
|
||||
if it.fresh { ce.model = bd_first_fill(ui_st, it, k, e) } else { ce.model = bd_fill(ui_st, it, k, e) }
|
||||
ce.inst = it
|
||||
ce.ctx = e.ctx
|
||||
ce.slot = k
|
||||
|
|
@ -34,6 +25,26 @@ function bd_class(ui_st: mut UiState, k: UiTpl, e: UiEnv, key: string, out: []Ui
|
|||
bd_kids(ui_st, root, ce, key, out)
|
||||
if len(out) > at { bd_pass_down(ui_st, out[at], k, e) }
|
||||
}
|
||||
# an instance's props and model, filled in place into the objects it keeps (a reused one's are kept)
|
||||
function bd_fill(ui_st: mut UiState, it: UiInst, k: UiTpl, e: UiEnv) -> Val {
|
||||
if it.props == null { it.props = Value.object() }
|
||||
let props = it.props
|
||||
Value.clear(props)
|
||||
for i in 0 .. len(k.keys) {
|
||||
let a = k.keys[i]
|
||||
if a != "class" and a != "style" and a != "id" { Value.put(props, a, ui_eval(ui_st, k.vals[i], e)) }
|
||||
}
|
||||
it.cls.props(it.ptr, props)
|
||||
if it.model == null { it.model = Value.object() }
|
||||
return it.cls.model(it.ptr, it.model)
|
||||
}
|
||||
# a new instance's first fill makes its props and model objects and every Value in them - once per
|
||||
# instance, which in_reuse bounds (a prompt's key hint first shown mid-walk was judged as a frame's keep)
|
||||
@alloc_ok("a new component instance's first build: its props and model, then kept or reused")
|
||||
function bd_first_fill(ui_st: mut UiState, it: UiInst, k: UiTpl, e: UiEnv) -> Val {
|
||||
it.fresh = false
|
||||
return bd_fill(ui_st, it, k, e)
|
||||
}
|
||||
# <Card class="wide" style="margin: 4px" id="c"> puts those on the card's own root element; when that
|
||||
# root is itself a component, each user in turn adds theirs (the outermost's id wins)
|
||||
function bd_pass_down(ui_st: mut UiState, n: UiNode, k: UiTpl, e: UiEnv) -> void {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ property UiInst {
|
|||
seen: int = 0
|
||||
props: Val = null # its props, filled again each frame into the same object
|
||||
model: Val = null # and its model, filled in place by the class's model()
|
||||
fresh: bool = false # made, not reused: its first build makes its props and model
|
||||
}
|
||||
# builds before an unmounted instance is mounted again: the tree that last named it is good for two
|
||||
const IN_SPARE_AFTER: int = 2
|
||||
|
|
@ -41,6 +42,7 @@ function in_reuse(ui_st: mut UiState, k: UiClass) -> UiInst {
|
|||
let it = new UiInst
|
||||
it.cls = k
|
||||
it.ptr = k.make()
|
||||
it.fresh = true
|
||||
return it
|
||||
}
|
||||
# after a build of `screen`: its instances the build did not reach are unmounted
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue