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

@ -28,7 +28,7 @@ function net__open(net_st: mut NetState, slot: int, ip: int, port: int, pid: int
p.recv_id = 0
p.acked = 0
p.ack_due = false
p.queue = new []NetMsg
net__queue_free(net_st, p)
p.closing = false
}
@ -37,7 +37,7 @@ export function np_close(net_st: mut NetState, slot: int) -> void {
let p = net_st.net__peers[slot]
p.on = false
p.closing = false
p.queue = new []NetMsg
net__queue_free(net_st, p)
}
# the written message, for one peer (a reliable one is kept until it is taken)
@ -45,15 +45,15 @@ export function np_queue(net_st: mut NetState, slot: int, kind: int, rel: bool)
if net_st.net__peers == null or slot < 0 or slot >= NET_PEERS { return }
let p = net_st.net__peers[slot]
if not p.on { return }
let m = new NetMsg
let m = net__msg_take(net_st)
m.kind = kind
m.rel = rel
m.id = 0
m.sent = -1.0
m.made = net_st.net__time
var n = net_st.net__wl
if n > NET_MTU - 40 { n = NET_MTU - 40 }
m.len = n
m.data = buffer(n)
nb_copy(m.data, 0, net_st.net__wb, 0, n)
if rel {
m.id = p.next_id