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

@ -72,9 +72,11 @@ export function nr_text(net_st: mut NetState, cap: int) -> string {
net_st.net__rbad = true
return ""
}
nb_copy(net_st.net__tb, 0, net_st.net__rb, net_st.net__rp, n)
let sb = net_st.net__tsb
sb_clear(sb)
for i in 0 .. n { sb_byte(sb, net_st.net__rb[net_st.net__rp + i]) }
net_st.net__rp += n
return text_of(net_st.net__tb, n)
return sb_intern(sb, net_st.net__ttb)
}
export function nr_bad(net_st: NetState) -> bool { return net_st.net__rbad }
@ -87,12 +89,16 @@ export function net_read(net_st: mut NetState, m: NetMessage) -> void {
net_st.net__rbad = false
}
# the message just written, as if it had come in (a loopback: a test, a host telling itself)
export function net_written(net_st: NetState) -> NetMessage {
let m = new NetMessage
# the message just written, as if it had come in (a loopback: a test, a host telling itself); the
# record is kept, so it is good until the next net_written
export function net_written(net_st: mut NetState) -> NetMessage {
if net_st.net__wr == null {
net_st.net__wr = new NetMessage
net_st.net__wr.data = buffer(NET_MTU)
}
let m = net_st.net__wr
m.from = net_st.net__my_pid
m.len = min(net_st.net__wl, NET_MTU)
m.data = buffer(m.len)
nb_copy(m.data, 0, net_st.net__wb, 0, m.len)
return m
}