Skip to content

Commit b50694e

Browse files
committed
Merge remote-tracking branch 'origin/fast/integration' into fast/j4-bun-loop
2 parents d38c304 + a5b9497 commit b50694e

10 files changed

Lines changed: 521 additions & 28 deletions

File tree

‎src/server/effects/mem.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Mem.settle (host.bend): nothing to settle in the native build (no GC heap
2+
// holds the thin index's build); the line to log is "".
3+
4+
#ifdef CID(Mem.settle)
5+
6+
Term mem_settle_run(Env e, Term* f, IoWork* w) {
7+
return term_pak(CID(SNil), 0);
8+
}
9+
10+
static void __attribute__((constructor)) mem_settle_use(void) {
11+
io_eff(CID(Mem.settle), mem_settle_run);
12+
}
13+
14+
#endif

‎src/server/effects/mem.js‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Mem.settle (host.bend): one full collection and a release of free memory,
2+
// at most once per process (after the boot's thin index is warm); the line
3+
// to log with its time and the RSS before and after, "" when nothing was done.
4+
let mem_settled = false;
5+
6+
function mem_settle() {
7+
if (mem_settled || typeof Bun === "undefined" || typeof Bun.gc !== "function") return "";
8+
mem_settled = true;
9+
const r0 = process.memoryUsage().rss;
10+
const t0 = Date.now();
11+
Bun.gc(true);
12+
if (typeof Bun.shrink === "function") Bun.shrink();
13+
const ms = Date.now() - t0;
14+
const r1 = process.memoryUsage().rss;
15+
return "memory settled after the thin index: one full collection in " + ms + " ms, rss " + Math.round(r0 / 1e6) + " MB -> " + Math.round(r1 / 1e6) + " MB";
16+
}
17+
18+
io_eff(CID(Mem.settle), mem_settle);

‎src/server/host.bend‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ import Base
66
def Clock.epoch() -> IO(U32):
77
import "./effects/host.js"
88

9+
# One full collection and a release of free memory, at most once per
10+
# process, called when the boot's thin index is warm (server.bend's
11+
# Hub.thin.warmed): on the JS target its build leaves ~0.9 GB of heap
12+
# capacity behind at the boot peak (3.35 GB → 2.44 GB measured on a copy of
13+
# the real log, 2026-10-22). Answers the line to log; "" when nothing was
14+
# done (the C build, or any later call). It goes once store mode keeps the
15+
# thin index small (only the recent threads).
16+
def Mem.settle() -> IO(String):
17+
import "./effects/mem.c"
18+
import "./effects/mem.js"
19+
920
# The event log from byte offset off (decimal text; "0" for all of it,
1021
# a line's start for a tail) to its end, read in one go: the text that
1122
# closes off a torn tail, the offset past the last whole line, then the

‎src/server/server.bend‎

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11012,22 +11012,46 @@ def Hub.thin.fetch(memory: Bool, +cfg: Cfg, +thread: String, +anchor: Nat) -> IO
1101211012
case True{}: IO.pure(TSTO.Page, TSTO.Page{Cfg.thin(cfg), THIN.Index.page(Cfg.thin(cfg), thread, anchor, 32n)})
1101311013
case False{}: TSTO.Ts.page(Cfg.thin.store(cfg), thread, anchor, 32n, Cfg.thin(cfg))
1101411014

11015-
def Hub.thin.render.page(+pg: TSTO.Page, h: Hub, +client: U32, +o: J.Json, +c: Client, +now: Nat, +context: ThinContext, +p: J.Json) -> IO(Hub):
11015+
def Hub.thin.render.page(+pg: TSTO.Page, h: Hub, +client: U32, +o: J.Json, +c: Client, +now: Nat, +context: ThinContext, +p: J.Json, +key: String, +ms: Nat) -> IO(Hub):
1101611016
match h:
1101711017
case Hub{+st, f, ls, cl, as, inbox, +cfg, note}:
1101811018
+web = String.eq(Client.thin.mode(c), "view-web")
11019+
+stream = TLIVE.Stream.get(Cfg.thin.streams(cfg), TV.Target.thread(st, J.Json.get_obj(p, "target")))
1101911020
+actor = TA.Actor.mail_cache(TA.Actor.refresh(ThinContext.actors(context), web, st, Hub.info(cfg),
1102011021
J.Json.obj([J.KV{"t", J.Str{"live"}}, J.KV{"items", J.Json.arr(Nil{})}]), now, p, ThinContext.view(context)), ThinContext.actors(context), Cfg.thin.mail(cfg))
11021-
Hub.thin.rendered(TA.Actor.render(actor, web, st, TSTO.Page.index(pg), p, Cfg.thin.epoch(cfg), now, TSTO.Page.ids(pg), TLIVE.Stream.get(Cfg.thin.streams(cfg), TV.Target.thread(st, J.Json.get_obj(p, "target")))),
11022+
Hub.thin.rendered(TA.Rendered.remember(TA.Actor.render(actor, web, st, TSTO.Page.index(pg), p, Cfg.thin.epoch(cfg), now, TSTO.Page.ids(pg), stream), key, ms, stream),
1102211023
Hub{st, f, ls, cl, as, inbox, cfg, note}, client, o, c, now, context)
1102311024

11024-
def Hub.thin.render(h: Hub, +client: U32, +o: J.Json, +c: Client, +now: Nat, +context: ThinContext, +anchor: Nat) -> IO(Hub):
11025+
def Hub.thin.render.full(h: Hub, +client: U32, +o: J.Json, +c: Client, +now: Nat, +context: ThinContext, +anchor: Nat, +p: J.Json, +key: String, +ms: Nat) -> IO(Hub):
1102511026
match h:
1102611027
case Hub{+st, f, ls, cl, as, inbox, +cfg, note}:
11027-
+p = Hub.thin.input(String.eq(J.Json.get_str(o, "m", ""), "view.action"), J.Json.get_obj(o, "p"), ThinContext.cid(context))
1102811028
do IO<Hub>:
1102911029
+pg : TSTO.Page <- Hub.thin.fetch(String.is_empty(Cfg.thin.store(cfg)), cfg, TV.Target.thread(st, J.Json.get_obj(p, "target")), anchor)
11030-
Hub.thin.render.page(pg, Hub{st, f, ls, cl, as, inbox, cfg, note}, client, o, c, now, context, p)
11030+
Hub.thin.render.page(pg, Hub{st, f, ls, cl, as, inbox, cfg, note}, client, o, c, now, context, p, key, ms)
11031+
11032+
# a view.update whose render memo still holds (thin-actor.bend's
11033+
# Memo.reply: only the live row can have changed) answers with it spliced
11034+
# (thin-splice.bend); anything else renders in full and is remembered
11035+
def Hub.thin.render.memo(+m: Maybe<&2, J.Json>, h: Hub, +client: U32, +o: J.Json, +c: Client, +now: Nat, +context: ThinContext, +anchor: Nat, +p: J.Json, +key: String, +ms: Nat) -> IO(Hub):
11036+
match m:
11037+
case Some{+res}:
11038+
Hub.thin.respond(h, client, o, res, c, context, now)
11039+
case None{}:
11040+
Hub.thin.render.full(h, client, o, c, now, context, anchor, p, key, ms)
11041+
11042+
def Hub.thin.render.at(h: Hub, +client: U32, +o: J.Json, +c: Client, +now: Nat, +context: ThinContext, +anchor: Nat, +ms: Nat) -> IO(Hub):
11043+
match h:
11044+
case Hub{+st, f, ls, cl, as, inbox, +cfg, note}:
11045+
+p = Hub.thin.input(String.eq(J.Json.get_str(o, "m", ""), "view.action"), J.Json.get_obj(o, "p"), ThinContext.cid(context))
11046+
+web = String.eq(Client.thin.mode(c), "view-web")
11047+
+thread = TV.Target.thread(st, J.Json.get_obj(p, "target"))
11048+
+key = TA.Memo.key(M.State.seq(st), J.Json.show(Hub.info(cfg)), p, anchor, ThinContext.view(context), web, thread)
11049+
Hub.thin.render.memo(TA.Memo.reply(TA.Actor.memos(ThinContext.actors(context)), String.eq(J.Json.get_str(o, "m", ""), "view.update"), key, ms, web,
11050+
TLIVE.Stream.get(Cfg.thin.streams(cfg), thread), thread, Cfg.thin.epoch(cfg), J.Json.get_obj(p, "target"), TA.Actor.loc(ThinContext.actors(context))),
11051+
Hub{st, f, ls, cl, as, inbox, cfg, note}, client, o, c, now, context, anchor, p, key, ms)
11052+
11053+
def Hub.thin.render(h: Hub, +client: U32, +o: J.Json, +c: Client, +now: Nat, +context: ThinContext, +anchor: Nat) -> IO(Hub):
11054+
IO.bind(Nat, Hub, IO.now(), +ms => Hub.thin.render.at(h, client, o, c, now, context, anchor, ms))
1103111055

1103211056
# a search page: over the whole index, or (with a store) over the
1103311057
# candidates it fetched (TSTO.Ts.search); the same rows either way
@@ -11161,11 +11185,26 @@ def Hub.thin.answer(ws: List<&2, ThinWait>, h: Hub) -> IO(Hub):
1116111185
h2 : Hub <- Hub.thin.rpc.now(h, client, o, now)
1116211186
Hub.thin.answer(tail, h2)
1116311187

11164-
def Hub.thin.warmed(h: Hub, i: THIN.Index, m: TMAIL.Cache) -> IO(Hub):
11188+
def Mem.settled.k(none: Bool, +line: String) -> IO(Unit):
11189+
match none:
11190+
case True{}:
11191+
IO.pure(Unit, Unit{})
11192+
case False{}:
11193+
Log.info(line)
11194+
11195+
def Mem.settled(+line: String) -> IO(Unit):
11196+
Mem.settled.k(String.is_empty(line), line)
11197+
11198+
def Hub.thin.warmed.k(h: Hub, i: THIN.Index, m: TMAIL.Cache) -> IO(Hub):
1116511199
match h:
1116611200
case Hub{st, f, ls, cl, as, inbox, +cfg, note}:
1116711201
Hub.thin.answer(List.reverse(&2, ThinWait, Cfg.thin.waiting(cfg)), Hub{st, f, ls, cl, as, inbox, Cfg.thin.warm(cfg, i, m), note})
1116811202

11203+
# the boot's thin index arrived: the JS heap is settled once (H.Mem.settle,
11204+
# until store mode keeps the index small), then the waiting reads answered
11205+
def Hub.thin.warmed(h: Hub, i: THIN.Index, m: TMAIL.Cache) -> IO(Hub):
11206+
IO.bind(String, Hub, H.Mem.settle(), line => IO.bind(Unit, Hub, Mem.settled(line), _ => Hub.thin.warmed.k(h, i, m)))
11207+
1116911208
def Hub.thin.read_guard(valid: Bool, h: Hub, +client: U32, +text: String, +now: Nat) -> IO(Hub):
1117011209
match valid:
1117111210
case False{}: IO.pure(Hub, h)
@@ -11209,10 +11248,20 @@ def Hub.rpc.thin_cap(thin: Bool, h: Hub, +client: U32, +text: String, +now: Nat)
1120911248
case True{}: Hub.rpc.thin_short(TVW.Wire.within(text, 262144n), h, client, text, now)
1121011249
case False{}: Hub.rpc.parse(h, client, text, now)
1121111250

11251+
# A request from no connected client is dropped (a client that left),
11252+
# except client 0: the hub's own jobs (GitJob.say: a thread's worktree, its
11253+
# notes; a dead push token) and the in-process window send theirs as 0, and
11254+
# a headless hub has no client 0. Dropping those lost every new thread's
11255+
# worktree, so its first turn never started (far_e2e on a headless hub).
11256+
def Hub.rpc.own(own: Bool, h: Hub, +client: U32, +text: String, +now: Nat) -> IO(Hub):
11257+
match own:
11258+
case True{}: Hub.rpc.thin_cap(False{}, h, client, text, now)
11259+
case False{}: IO.pure(Hub, h)
11260+
1121211261
def Hub.rpc.client(c: Maybe<&2, Client>, h: Hub, +client: U32, +text: String, +now: Nat) -> IO(Hub):
1121311262
match c:
1121411263
case Some{c}: Hub.rpc.thin_cap(Client.thin(c), h, client, text, now)
11215-
case None{}: IO.pure(Hub, h)
11264+
case None{}: Hub.rpc.own(U32.is_eq(client, 0), h, client, text, now)
1121611265

1121711266
def Hub.rpc(h: Hub, +client: U32, +text: String, +now: Nat) -> IO(Hub):
1121811267
match h:

‎src/server/thin-actor.bend‎

Lines changed: 76 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,27 @@ import ../core/thin-live.bend as TL
1111
import ../web/app.bend as A
1212
import ../web/mail-actions.bend as MA
1313
import ../mobile/hubs.bend as H
14+
import ./thin-splice.bend as S
15+
import ../core/i18n.bend as I
1416

1517
# Private, connection-owned UI state. It never enters a client snapshot or
1618
# persisted event. Keep it behind a List in the connection context so the
1719
# native ABI does not flatten a second full Ui into every Client argument.
20+
# memo: the last full render's reply and what it was made of (at most
21+
# one; thin-splice.bend writes only the live row into it until anything
22+
# else changes or a second passes: Memo.splice)
23+
type Memo is Data:
24+
Memo{key: String, clock: Nat, partial: Bool, result: J.Json}
25+
1826
type Actor is Data:
19-
Actor{ui: U.Ui, view: String, target: J.Json, pending: Map<&2, String>, reads: List<&2, J.Json>, dirty: Bool}
27+
Actor{ui: U.Ui, view: String, target: J.Json, pending: Map<&2, String>, reads: List<&2, J.Json>, dirty: Bool, memo: List<&2, Memo>}
2028

2129
type Rendered is Data:
2230
Rendered{actor: Actor, result: J.Json}
2331

2432
def Actor.ui( +a: Actor) -> U.Ui:
2533
match a:
26-
case Actor{u, _, _, _, _, _}: u
34+
case Actor{u, _, _, _, _, _, _}: u
2735

2836
def Actor.scope(+target: J.Json) -> String:
2937
J.Json.show(V.Target.json(J.Json.get_str(target, "kind", ""), J.Json.get_str(target, "id", "")))
@@ -114,28 +122,28 @@ def Actor.merge( +fresh: U.Ui, +old: U.Ui, +same: Bool, +thread: String, +presen
114122
M.Time.max(rid, rid2), want, error, note, Actor.prefs(Map.to_list(&2, String, nf2), nf), outbox, stores}
115123

116124
def Actor.make(+u: U.Ui, +view: String, +target: J.Json) -> Actor:
117-
Actor{u, view, target, Map.new(&2, String), Nil{}, False{}}
125+
Actor{u, view, target, Map.new(&2, String), Nil{}, False{}, Nil{}}
118126

119127
def Actor.refresh( +xs: List<&2, Actor>, +web: Bool, +st: M.State, +info: J.Json, +live: J.Json, +now: Nat, +p: J.Json, +view: String) -> Actor:
120128
match xs:
121129
case Nil{}: Actor.make(V.Session.current(web, st, info, live, now, Actor.safe_input(st, p)), view, J.Json.get_obj(p, "target"))
122-
case Actor{old, oldView, +target, pending, reads, dirty} <> _:
130+
case Actor{old, oldView, +target, pending, reads, dirty, _} <> _:
123131
+input = Actor.safe_input(st, p)
124132
+thread = V.Target.thread(st, J.Json.get_obj(p, "target"))
125133
+fresh = V.Session.current(web, st, info, live, now, input)
126134
+same = Bool.and(String.eq(oldView, view), W.Target.same(target, J.Json.get_obj(p, "target")))
127135
Actor{V.Session.renderer(web, U.Ui.info_merge(Actor.merge(fresh, old, same, thread, Maybe.is_some(&2, J.Json, J.Json.get(J.Json.get_obj(J.Json.get_obj(input, "session"), "drafts"), thread))), info), p),
128-
view, J.Json.get_obj(p, "target"), Bool.pick(Map<&2, String>, same, pending, Map.new(&2, String)), Bool.pick(List<&2, J.Json>, same, reads, Nil{}), dirty}
136+
view, J.Json.get_obj(p, "target"), Bool.pick(Map<&2, String>, same, pending, Map.new(&2, String)), Bool.pick(List<&2, J.Json>, same, reads, Nil{}), dirty, Nil{}}
129137

130138
# The hub's canonical projection is shared; each actor keeps its own pages,
131139
# drafts, request slots and exact scope. Compare only the selected body's
132140
# newest identity across authoritative states, never its text or full log.
133141
def Actor.mail_cache(+a: Actor, previous: List<&2, Actor>, cache: TM.Cache) -> Actor:
134142
match a previous:
135-
case Actor{u, view, target, pending, reads, dirty} Nil{}:
136-
Actor{TM.Cache.install(cache, u), view, target, pending, reads, dirty}
137-
case Actor{u, view, target, pending, reads, dirty} old <> _:
138-
Actor{TM.Cache.refresh(cache, u, Actor.ui(old)), view, target, pending, reads, dirty}
143+
case Actor{u, view, target, pending, reads, dirty, memo} Nil{}:
144+
Actor{TM.Cache.install(cache, u), view, target, pending, reads, dirty, memo}
145+
case Actor{u, view, target, pending, reads, dirty, memo} old <> _:
146+
Actor{TM.Cache.refresh(cache, u, Actor.ui(old)), view, target, pending, reads, dirty, memo}
139147

140148
def Actor.rpc(+command: J.Json) -> J.Json:
141149
Maybe.default(&2, J.Json, J.Json.parse(J.Json.get_str(command, "text", "")), J.Null{})
@@ -166,16 +174,16 @@ def Actor.reads( +cs: List<&2, J.Json>, +acc: List<&2, J.Json>) -> List<&2, J.Js
166174

167175
def Actor.accept( +a: Actor, +r: V.ActResult, +queue: Bool) -> Actor:
168176
match a r:
169-
case Actor{_, view, +target, pending, reads, dirty} V.ActResult{u, +cs}:
177+
case Actor{_, view, +target, pending, reads, dirty, memo} V.ActResult{u, +cs}:
170178
Actor{u, view, target, Actor.note(cs, pending, Actor.scope(target)),
171-
List.append(&2, J.Json, reads, Bool.pick(List<&2, J.Json>, queue, Actor.reads(cs, Nil{}), Nil{})), dirty}
179+
List.append(&2, J.Json, reads, Bool.pick(List<&2, J.Json>, queue, Actor.reads(cs, Nil{}), Nil{})), dirty, memo}
172180

173181
def Actor.mail_ready( +a: Actor) -> Actor:
174182
Actor.accept(a, V.ActResult.web(MA.MA.after(U.Mailv.sync(U.Act{Actor.ui(a), Nil{}}))), True{})
175183

176184
def Actor.origin( +a: Actor, +origin: String) -> Actor:
177185
match a:
178-
case Actor{u, view, target, pending, reads, dirty}: Actor{U.Ui.info_set(u, "origin", origin), view, target, pending, reads, dirty}
186+
case Actor{u, view, target, pending, reads, dirty, memo}: Actor{U.Ui.info_set(u, "origin", origin), view, target, pending, reads, dirty, memo}
179187

180188
def Actor.mail_context_if( +shown: Bool, +u: U.Ui) -> J.Json:
181189
match shown:
@@ -202,7 +210,7 @@ def Actor.receive( +web: Bool, +u: U.Ui, +key: String, +now: Nat, +o: J.Json) ->
202210

203211
def Actor.mark_dirty( +a: Actor) -> Actor:
204212
match a:
205-
case Actor{u, view, target, pending, reads, _}: Actor{u, view, target, pending, reads, True{}}
213+
case Actor{u, view, target, pending, reads, _, _}: Actor{u, view, target, pending, reads, True{}, Nil{}}
206214

207215
def Actor.now( +u: U.Ui) -> Nat:
208216
match u:
@@ -215,26 +223,26 @@ def Actor.reply_if( +owned: Bool, +a: Actor, +web: Bool, +key: String, +o: J.Jso
215223

216224
def Actor.reply(+a: Actor, +web: Bool, +key: String, +o: J.Json) -> Actor:
217225
match a:
218-
case Actor{u, view, +target, +pending, reads, dirty}:
226+
case Actor{u, view, +target, +pending, reads, dirty, memo}:
219227
+id = J.Json.as_raw(J.Json.get(o, "id"), "")
220228
Actor.reply_if(Bool.and(String.eq(J.Json.get_str(o, "t", ""), "reply"), String.eq(Actor.pending_scope(pending, id), Actor.scope(target))),
221-
Actor{u, view, target, Map.del(&2, String, pending, id), reads, dirty}, web, key, o)
229+
Actor{u, view, target, Map.del(&2, String, pending, id), reads, dirty, memo}, web, key, o)
222230

223231
def Actor.clean( +a: Actor) -> Actor:
224232
match a:
225-
case Actor{u, view, target, pending, _, _}: Actor{u, view, target, pending, Nil{}, False{}}
233+
case Actor{u, view, target, pending, _, _, memo}: Actor{u, view, target, pending, Nil{}, False{}, memo}
226234

227235
def Actor.queued( +a: Actor) -> List<&2, J.Json>:
228236
match a:
229-
case Actor{_, _, _, _, reads, _}: reads
237+
case Actor{_, _, _, _, reads, _, _}: reads
230238

231239
def Actor.dirty( +a: Actor) -> Bool:
232240
match a:
233-
case Actor{_, _, _, _, _, dirty}: dirty
241+
case Actor{_, _, _, _, _, dirty, _}: dirty
234242

235243
def Actor.capacity( +a: Actor) -> Bool:
236244
match a:
237-
case Actor{_, _, _, pending, reads, _}: Bool.and(Nat.is_le(List.length(&2, String, Map.keys(&2, String, pending)), 128n), Nat.is_le(List.length(&2, J.Json, reads), 16n))
245+
case Actor{_, _, _, pending, reads, _, _}: Bool.and(Nat.is_le(List.length(&2, String, Map.keys(&2, String, pending)), 128n), Nat.is_le(List.length(&2, J.Json, reads), 16n))
238246

239247
# A queued read is useful only to the exact surviving connection incarnation
240248
# and view that produced it. Equal RPC ids on another socket grant nothing.
@@ -244,3 +252,52 @@ def Job.valid(+actualClient: U32, +jobClient: U32, +actualGen: U32, +jobGen: U32
244252

245253
def Control.fresh(+id: Nat, +last: Nat) -> Bool:
246254
Bool.and(Nat.is_gt(id, Nat.mul(65536n, 2147483648n)), Bool.and(Nat.is_le(id, P.Session.nat.max()), Nat.is_gt(id, last)))
255+
256+
# The render memo (thin-splice.bend)
257+
# ----------------------------------
258+
259+
def Actor.memos(xs: List<&2, Actor>) -> List<&2, Memo>:
260+
match xs:
261+
case Actor{_, _, _, _, _, _, memo} <> _: memo
262+
case Nil{}: Nil{}
263+
264+
def Actor.loc(xs: List<&2, Actor>) -> I.Loc:
265+
match xs:
266+
case Actor{u, _, _, _, _, _, _} <> _: U.Lang.loc(u)
267+
case Nil{}: I.En{}
268+
269+
def Actor.remember(+a: Actor, +m: Memo) -> Actor:
270+
match a:
271+
case Actor{u, view, target, pending, reads, dirty, _}: Actor{u, view, target, pending, reads, dirty, [m]}
272+
273+
# what a render is made of but its live row: the read model's sequence, the
274+
# hub's info, the request but its revisions, the page anchor, the view, the
275+
# renderer and the thread (a reply arriving clears the memo: Actor.reply_if)
276+
def Memo.request(+p: J.Json) -> J.Json:
277+
match p:
278+
case J.Obj{+fs}: J.Obj{V.Obj.drop(V.Obj.drop(fs, "requestRevision"), "viewRevision")}
279+
case _: p
280+
281+
def Memo.key(+seq: Nat, +info: String, +p: J.Json, +anchor: Nat, +view: String, +web: Bool, +thread: String) -> String:
282+
J.Json.show(J.Json.obj([J.KV{"seq", J.Json.nat(seq)}, J.KV{"info", J.Str{info}}, J.KV{"p", Memo.request(p)}, J.KV{"anchor", J.Json.nat(anchor)},
283+
J.KV{"view", J.Str{view}}, J.KV{"web", J.Flag{web}}, J.KV{"thread", J.Str{thread}}]))
284+
285+
def Memo.reply.k(+ok: Bool, +res: J.Json, +web: Bool, +stream: TL.Stream, +thread: String, +epoch: String, +target: J.Json, +lc: I.Loc) -> Maybe<&2, J.Json>:
286+
match ok:
287+
case True{}: S.Splice.reply(web, res, stream, thread, epoch, target, lc)
288+
case False{}: None{}
289+
290+
# the memo's reply with only the live row and window new, when nothing else
291+
# can have changed: the same key, at most a second old (clock text), a live
292+
# row now with the same chunk marker as then; None: render in full
293+
def Memo.reply(ms: List<&2, Memo>, +update: Bool, +key: String, +clock: Nat, +web: Bool, +stream: TL.Stream, +thread: String, +epoch: String, +target: J.Json, +lc: I.Loc) -> Maybe<&2, J.Json>:
294+
match ms:
295+
case Nil{}: None{}
296+
case Memo{+k, +at, +partial, +res} <> _:
297+
Memo.reply.k(Bool.and(update, Bool.and(String.eq(k, key), Bool.and(Nat.is_ge(clock, at), Bool.and(Nat.is_lt(Nat.sub(clock, at), 1000n),
298+
Bool.and(Nat.is_gt(TL.Stream.size(stream), 0n), Bool.or(Bool.and(partial, S.Splice.partial(stream)), Bool.and(Bool.not(partial), Bool.not(S.Splice.partial(stream))))))))), res, web, stream, thread, epoch, target, lc)
299+
300+
# a full render remembered for the next ones (clock: ms)
301+
def Rendered.remember(r: Rendered, +key: String, +clock: Nat, +stream: TL.Stream) -> Rendered:
302+
match r:
303+
case Rendered{+a, +res}: Rendered{Actor.remember(a, Memo{key, clock, S.Splice.partial(stream), res}), res}

0 commit comments

Comments
 (0)