ludic.net: a message's record, bytes and lists kept - queued ones back to a pool once sent or taken, the inbox's two drains on, a read text interned

np_queue made a NetMsg and a buffer per message, every flush a new keep list, and every message
that came in a NetMessage and a buffer; nr_text a new string per text read. A party plays at
dozens a second, so all of it is kept now: a pool of MTU-sized records for the queue (a peer's two
lists swapped by the flush), the inbox's records in two halves swapped when a message finds the
inbox empty, net_written's one record, a relay hello's and a STUN request's bytes in one scratch
buffer, and the texts read out interned. Tests: 6000 messages with the heap flat (Os.heap_bytes),
and an inbox record that holds still across a drain and comes back two drains on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-28 13:25:46 +03:00
parent e6729b3123
commit ca69a3f9ae
11 changed files with 134 additions and 20 deletions

View file

@ -0,0 +1,36 @@
# pool.ludic - a message's record and its bytes are kept, never made again: a party sends and takes
# dozens a second for as long as it plays, and Ludic frees nothing. A queued one goes back when it is
# taken or goes stale; an inbox one comes back two drains after it was handed out
function net__msg_take(net_st: mut NetState) -> NetMsg {
if len(net_st.net__free) > 0 { return List.pop(net_st.net__free) }
let m = new NetMsg
m.data = buffer(NET_MTU)
return m
}
# everything a peer had queued, back to the pool (its slot opened again, or let go)
function net__queue_free(net_st: mut NetState, p: NetPeer) -> void {
for i in 0 .. len(p.queue) { push(net_st.net__free, p.queue[i]) }
List.clear(p.queue)
}
# the halves swap whenever a message finds the inbox empty (everything before it drained or
# cleared), so a reader of the last drain's list never sees one change
function net__in_take(net_st: mut NetState) -> NetMessage {
if q_len(net_st.net__inbox) == 0 and net_st.net__inn > 0 {
net_st.net__in_on_b = not net_st.net__in_on_b
net_st.net__inn = 0
}
var pool = net_st.net__ina
if net_st.net__in_on_b { pool = net_st.net__inb }
if net_st.net__inn >= len(pool) {
let m = new NetMessage
m.data = buffer(NET_MTU)
push(pool, m)
}
let m = pool[net_st.net__inn]
net_st.net__inn += 1
return m
}
export function net_spare_count(net_st: NetState) -> int { return len(net_st.net__free) }