Reduce Zig ReleaseFast runtime codegen graph - #450
Conversation
|
Diagnostic attempt 1 findings:
The second commit changes the trace to wrap the first failing |
|
Diagnostic update from run 31054869045:
The clean discriminator remains two independent cache clones from one identical starting state: build-runner + |
|
Cache-isolated A/B result from run 31057090590:
Conclusion: The diagnostic check is red only because it asserted the previously expected server-fails/direct-succeeds split; both replays actually exited 0. |
…m64-bad-alloc # Conflicts: # zig/build.zig # zig/pkg/antfly/src/api/table_reads.zig
Outcome
Make ARM64-musl
ReleaseFastthe release target without a larger runner, swap, or-j1. Antfly still ships one executable, standalone still always includes embedded inference, and the executable plus C ABI library now build in one memory-budgeted graph.The complete clean-cache ARM64 Linux musl archive build now takes 6m28s, down from 14m16s for the previous four-unit executable plus separately compiled CAPI kernel.
Production design
The executable links four independently code-generated units behind hidden C ABIs:
api_kernel: public API request/handler machinerycli: remote CLI and HA administrationantfly-storage-kernel: data, metadata, serverless, standalone, Lite, and the public opaque CAPI implementationinference: inference commands and standalone's embedded inference hostData, metadata, serverless, standalone, and CAPI deliberately share the PIC storage-kernel archive because their storage graphs almost completely overlap. The executable,
libantfly, andlibantfly_zig_capiall consume that exact compiled archive. The shared-library link uses a private anchor and private trap-only resolutions for executable-only API/inference references, so those unrelated archives are not retained and their symbols are not exported.Standalone/focused CAPI builds retain a dedicated
capi_root.zigfacade and standalone PIC object. The existingcapi/root.zigpublic module is unchanged.The packaging script patches Zig 0.16's build runner for aggregate
max_rssaccounting and supplies a 20,971,520,000-byte scheduling budget. API + CLI + storage kernel form the initial 19 GiB claim group; as the small units finish, inference can overlap the kernel within the same budget.Measured result
Fresh isolated caches, pinned Zig 0.16, ARM64 Linux musl,
ReleaseFast, stripped, baseline CPU, no-j1:The final CAPI link took 1s and 224 MB RSS. The build completed successfully; the surrounding macOS
/usr/bin/timereturned nonzero only because its post-buildsysctl kern.clockrateprobe is sandbox-denied.Artifact tradeoff:
libantfly.so: 16,554,992 -> 28,297,616 bytes (+11,742,624; 70.9%)The 55 MB form that linked API and inference into the shared library was explicitly rejected. The accepted 27 MB library exports the public
antfly_db_*ABI but not runtime, API-kernel, inference-host, or link-anchor symbols.Compiler-graph reduction
The original five authoritative compiler graphs contained 2,147 repository-file instances but only 1,204 unique files: 943 duplicate analyzed/code-generated instances. Storage accounted for 255 duplicate instances.
Reusing the distributed/storage archive removes the separate CAPI compiler graph:
This achieves the dominant ownership/codegen win at a compiled artifact boundary using the existing opaque runtime and CAPI ABIs. Data, metadata, and standalone intentionally remain co-located inside that kernel, so a mechanical rewrite of every internal
DBuse into wire callbacks is no longer required for the release critical path. Finer opaque handles remain useful only if those roles need to be split into separate compiler units later.Failure diagnosis
The evidence does not support ordinary runner OOM: the original
std::bad_allococcurred with zero cgroup OOM events and only about 18–20 GB peak cgroup memory, while a direct compiler replay without Zig's--listen=-compiler-server protocol succeeded. The practical fix combines a smaller number of independently optimized graphs with corrected Zig 0.16 build-runnermax_rssadmission accounting.Verification
ReleaseFastexecutable + C ABI graph: 30/30 steps passedantfly_db_openis exported and private executable ABI symbols are absent