Skip to content

Runtime build: built-in files as string literals (lower compile memory) - #235

Merged
phantoslayer21 merged 1 commit into
mainfrom
param/embed-strings
Nov 15, 2026
Merged

phantoslayer21 merged 1 commit into
mainfrom
param/embed-strings

Conversation

@phantoslayer21

Copy link
Copy Markdown
Owner

The runtime library's built-in files (clean/runner/build.py write_embedded -> embedded_files.cpp) were written as brace lists of decimal bytes: one compiler node per byte. Compiling that single generated file was the memory peak of every runtime build. They are now string literals in 64-byte pieces (3-digit octal escapes, printable bytes as themselves). The library holds the same bytes, and the table line keeps its exact format, which test_no_model_k.py parses.

Measured on one development build folder (Model L runtime, 133 built-in files):

  • embedded_files.cpp: 95 MB -> 78 MB.
  • Runtime build (--runtime-only), peak system memory on a 32 GB machine with other work running:
    • Before: 79.6 % and 80.6 % (two complete builds); later attempts were stopped by a memory guard at 82 %.
    • After: 76.3 % and 71.8 %.
  • Build time: 75 s -> 50 s and 45 s.

Byte proof: clean/tests/test_embedded_table.py compiles the runtime's own lookup (embedded.cpp) with the generated table and a small harness (clean/tests/embed_dump.cpp). It reads every entry back through wg_read_file and compares its SHA-256 with the source file.

  • Unit tests: synthetic files covering every byte value, an empty file, and text with quotes, backslashes and ?? sequences, plus a mutant with one changed byte, which the test catches. 2 tests, OK.
  • --build on the real folder above: 133 files, 26,122,717 bytes, 0 mismatches.

MSVC would hit its 64 KB string-literal limit, so the generated file stops with #error when a file is larger than that. Only clang++ and g++ build the runtime (find_host_cxx).

…lists

write_embedded wrote every built-in file (all code objects, each also under its gfx1201 name, and every DXIL of
dx12/) as a brace list of decimal bytes: tens of millions of integer elements in one generated embedded_files.cpp, one
compiler node each. Compiling that one file was the memory peak of the runtime build.
Each file is now one string literal in adjacent 64-byte pieces (3-digit octal escapes, printable bytes as themselves):
the same bytes in the library, the same table line, a smaller file and far less compiler memory. A runtime built by
MSVC would hit its 64 KB string-literal limit: the generated file says so with #error (clang++ and g++ build the
runtime).

clean/tests/test_embedded_table.py: the runtime's own lookup (wg_read_file, through clean/tests/embed_dump.cpp) walks
the compiled table; every file's SHA-256 equals its source file's (synthetic files with every byte value, an empty
file, quotes / backslashes / trigraph text; a mutant with one changed byte is caught), and a --build mode for the table
of a real build folder.

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
@phantoslayer21
phantoslayer21 marked this pull request as ready for review November 15, 2026 07:07
@phantoslayer21
phantoslayer21 merged commit 7da79ab into main Nov 15, 2026
9 checks passed
@phantoslayer21
phantoslayer21 deleted the param/embed-strings branch November 15, 2026 07:07
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