Repository navigation
Description
What
include/morph/ui/interpreter.hpp is 11,077 lines with 3 templates and 174 inline functions. morph is a header-only INTERFACE target, so every translation unit that reaches the UI layer re-parses and re-checks the whole interpreter. Including that header and nothing else peaks at 1.8 GB in clang's front end. morph/client/source.hpp and morph/client/shell.hpp reach 2.3 GB.
That per-TU floor is what makes CI legs on GitHub-hosted runners (4 vCPU, 16 GB) run out of memory. At ninja's default 6 jobs, six such compiles exceed the runner's RAM, and the job dies with exit 143 or "The hosted runner lost communication with the server", with no compiler error.
Verification status
Measured on feat/lims-erp at 5d0f39c56, clang 23.1.4, with the flags of the clang-coverage preset's compile command for examples/lims/screens/tests/test_lims_ignition_screen.cpp. Peak RSS comes from RUSAGE_CHILDREN around the clang++ invocation, one compile at a time on an otherwise idle slot.
Front end only (-fsyntax-only), one #include per file:
109 MB <string>
338 MB <glaze/glaze.hpp>
632 MB <morph/core/bridge.hpp>
779 MB <morph/core/remote.hpp>
726 MB <morph/ui/document.hpp>
1818 MB <morph/ui/interpreter.hpp>
1306 MB <morph/ui/service.hpp>
1406 MB <morph/ui/chat/service.hpp>
2291 MB <morph/client/source.hpp>
2293 MB <morph/client/shell.hpp>
605 MB <morph/ui/testing/recording_backend.hpp>
The whole test TU, test_lims_ignition_screen.cpp:
full compile, coverage flags 3432 MB
without coverage 3405 MB
without coverage, -g0 3097 MB
front end only 2799 MB
the file's #include lines alone 3106 MB (full compile, coverage flags)
So about 90% of that test's memory is its includes, and the test body adds about 300 MB. Splitting large test files does not help, because each part pays the same floor. ninja -t deps in a clang-coverage build: 74 of 596 objects depend on interpreter.hpp.
A -ftime-trace of the same TU (without coverage, -g0): 32.9 s front end out of 36.8 s, 17.1 s in Source (parsing), 20.8 s in function instantiation. No single instantiation is above 0.52 s, so the cost is spread out, not one runaway template.
Not verified:
- GCC and MSVC memory. Only clang was measured.
- Master's TU-level figure. The local master build tree was configured against a newer layout, so master-side compiles of the lims tests stopped at a missing header. Two files that compiled on both sides:
examples/lims_gallery/src/screens/console.cpp2389 → 2564 MB andreview.cpp2382 → 2555 MB, master → branch. - How much a split would save. The suggestion below is inferred from the inline/template ratio, not prototyped.
Suggested direction
Most of interpreter.hpp is non-template code. Moving those bodies into a compiled translation unit would turn a per-TU cost into a one-time cost. The same likely applies to document.hpp (5.6K lines), service.hpp and expression.hpp. That changes morph from header-only to having a compiled part, which affects find_package(morph CONFIG) consumers and the install/export set. That is a design decision, which is why this is filed rather than done in place.
CI is currently kept under the limit by building the Linux legs with --parallel "$(nproc)". That bounds the symptom but does not reduce the cost.
What would change the verdict
Close this if interpreter.hpp alone drops well below 1 GB front-end peak, measured the same way, or if the project decides header-only is worth this cost and records that in docs/spec/. Reopen if a hosted Linux leg dies with exit 143 or "lost communication" at one compile per CPU.
Activity
Yaraslaut commentedon Nov 15, 2026
Triage: valid. Part A is done; Part B is what is left.
Part A landed in #1120 (
5b6a431db).morph::morphis a compiled STATIC library, and the non-template UI code is insrc/ui/*.cpp. The memory win was measured on gcc-release (peak RSS, master → branch):test_ui_shell_parts: 5640 MB → 2380 MB.test_ui_interpreter_commands: 4683 MB → 2464 MB.On #1120's last full CI run, the Application ladder compiled all of its translation units and failed only on tests, not on memory. The SQLite fix for those tests went into #1120 too, but #1120 merged before its final CI run finished, so master's CI has the last word.
Part B: a
MORPH_BUILD_SHAREDoption that buildsmorph::morphas a shared library.MORPH_API, fromGenerateExportHeader, must mark every non-template symbolsrc/defines, so the Windows (cl, clangcl) and Linux shared builds link.find_package(morph CONFIG)consumability must hold in both modes.include/morph, so it runs when no other lane holds those headers.Done when a shared build links and passes the test suite on Linux and Windows CI, and the install consumer check passes in both modes.