runtime: Log, DateTime.format, Input.text, Path, Mime, Fs, Os and Text keep nothing per call

Found by reading every builtin (Os.platform's 8 KB per call started it). Log builds its line only at
or above the threshold and frees it; DateTime.format folds through + so its pieces go; Input.text
encodes into one buffer; Path/Mime/Fs/Os free their temporaries on every path; string results of
Text/Path/Mime/DateTime/Os dirs are fresh and Text frees a fresh argument. Reseeded.
runtime_temps.ludic: 19.8 MB -> 0 over 20,000 rounds, 64 KB -> 0 over 200 of file work; clean under
MallocScribble. string_temps still 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-28 13:55:49 +03:00
parent 404ee2ee3b
commit 254097657e
11 changed files with 38168 additions and 37714 deletions

View file

@ -451,7 +451,10 @@ function input_text(rt_input_st: mut RtInputState) -> string {
if rt_input_st.in_text_buf == null { rt_input_st.in_text_buf = words(64) }
let n = win_text(rt_input_st.in_text_buf, 64)
if n <= 0 { return "" }
var out = ""
# one buffer for the whole text, four bytes a unit at most: a string joined a character at a time
# kept every shorter one and each character's own buffer
let out = bytes(n * 4 + 1)
var at = 0
var i = 0
while i < n {
var c = rt_input_st.in_text_buf[i]
@ -460,10 +463,29 @@ function input_text(rt_input_st: mut RtInputState) -> string {
let lo = rt_input_st.in_text_buf[i + 1]
if lo >= 56320 and lo < 57344 { c = 65536 + ((c - 55296) * 1024) + (lo - 56320); i = i + 1 }
}
out = out + in_utf8(c)
at = in_utf8_into(out, at, c)
i = i + 1
}
return out
out[at] = 0
let s: string = out
return s
}
# one code point's UTF-8 bytes into out at `at`; where the next one goes
function in_utf8_into(out: bytes, at: int, c: int) -> int {
if c < 128 {
out[at] = c
return at + 1
}
if c < 2048 {
out[at] = 192 | (c >> 6); out[at + 1] = 128 | (c & 63)
return at + 2
}
if c < 65536 {
out[at] = 224 | (c >> 12); out[at + 1] = 128 | ((c >> 6) & 63); out[at + 2] = 128 | (c & 63)
return at + 3
}
out[at] = 240 | (c >> 18); out[at + 1] = 128 | ((c >> 12) & 63); out[at + 2] = 128 | ((c >> 6) & 63); out[at + 3] = 128 | (c & 63)
return at + 4
}
# one code point as a UTF-8 string
function in_utf8(c: int) -> string {