Skip to content

rt: a Console capture reuses its buffer and returns a tight copy (s2c self-compile: page faults -86%, peak -30 MB) - #101

Merged
vic merged 1 commit into
mainfrom
capture-reuse
Nov 13, 2026
Merged

vic merged 1 commit into
mainfrom
capture-reuse

Conversation

@vic

@vic vic commented Nov 13, 2026

Copy link
Copy Markdown
Owner

What

A Console capture (captureBegin .. captureEnd) reuses the buffer of the last ended capture and returns its text as a tight copy. Before, rt_capture_begin started every capture on a fresh malloc block (4 KiB) that lived until the program ended.

Why

s2c compiling itself captures 7,468 times (Mem.fresh builds the name x#n with a capture). Those blocks were 86% of its page faults and 30 MB of its peak:

s2c self-compile (zig -O1 static) before after
page faults (perf, user) 8,617 1,214
peak RSS 417,484 KB 387,884 KB
mmap calls 988 68
instructions 6.153 G 6.154 G
output == seed == seed

Measured first as a stub on a scratch copy of the runtime, then landed as the same change (ticket in vic/evidence).

Test

tests/s2/prog/capture_many.srs: 20,000 short captures; the peak RSS (VmHWM) after them must stay under twice the peak after the first 100, and the first captured text must still read x#0 at the end. Old runtime: grew (81.9 MB, 20,314 faults). New: flat, kept (3.1 MB, 391 faults).

Mutants, both killed by the test: no buffer reuse (grew); returning the shared buffer instead of a copy (lost).

Gate: tests/run.sh green on this tree (log in the PR checks).

… returns its text as a tight copy; before, every capture kept a fresh 4 KiB malloc block for the program's lifetime (s2c self-compile, 7,468 captures in Mem.fresh: page faults 8,617 -> 1,214, peak RSS 417.5 -> 387.9 MB, same output). Test prog/capture_many: 20,000 captures keep the peak flat and the first text intact
@vic
vic merged commit 196ce09 into main Nov 13, 2026
3 checks passed
@vic
vic deleted the capture-reuse branch November 13, 2026 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant