Template¶
Compile cost in yggdrasil, loki, tyr and runir is dominated by the C++ front end: template instantiation and the headers that trigger it (Include), not optimization or LTO. These rules keep translation units (TUs) small. They apply to all four repositories and are maintained only here; the other repositories link to this page.
Goal: minimal compiler memory (max RSS of cc1plus) and time per TU in a Release + LTO build with GCC, with a
coherent structure that every repository follows.
Instantiation¶
T1 measured Explicitly instantiate when the same instantiation is repeated in many TUs and the declaration is cheap.
- Name:
template-explicit-instantiation
Define the members out of class: members defined in the class body are implicitly inline and GCC still instantiates them in every TU that uses them, despite
extern template. This includes the constructors and the destructor: declare them in the class and define them out of class (~T();andtemplate<...> T<...>::~T() = default;), or every TU that creates or destroys an object instantiates the destructors of all its members. Instantiate the whole class (template class T<...>;), not only its out-of-class members: underextern template, GCC also calls inline members it does not inline, so the library must provide them too.T2 judgment Prefer hiding definitions over
extern template.- Name:
template-hidden-definitions
Put the definitions in
detail/<name>_impl.hpp, include it only from the instantiating sources (and under<PROJECT>_HEADER_INSTANTIATION), and instantiate in the library. Users then only link. Headers that the definitions need include the declarations as<name>_decl.hpp, and only the public<name>.hppadds the definitions under<PROJECT>_HEADER_INSTANTIATION, so that build mode has no include cycle. Build it once after moving definitions. Anextern templatedeclaration of a class instantiates the class definition in every includer, so long extern lists or externs over heavy classes cost more than they save. Compile a shared library with-fno-semantic-interposition(GCC): otherwise calls between its own exported functions go through the PLT and are not inlined, so small hot functions moved out of headers become calls.T3 measured Make extern lists opt-in when the definitions must stay visible.
- Name:
template-opt-in-extern-lists
Put
extern templatedeclarations for widely shared instantiations (such as the symbol storage of every symbol type) in a separatedetail/<name>_instantiations.hppthat only the TUs doing that work include, e.g. parsers and translators that intern every type. Including such a list everywhere costs every light TU the class instantiations. Keep the list in the main header instead when nearly every includer does the work: in tyr, removing it from the repository headers made 60 TUs heavier and one lighter. Decide by measuring both, in the full build: a standalone probe of the same command can show a gain the build does not. Extern lists pay off for classes whose member bodies are heavy and used by many TUs (interning: hashing, lookup, insertion). They lose for classes whose cost is the class definition itself (object pools, builder storage, relation storage): the declaration instantiates the definition in every includer and saves little. The instantiating sources of a list also lengthen the library’s LTO link, a serial step of the build; peak build memory decides: drop a list only if that does not raise the peak at the build’s parallelism. Opt-in lists rely on the library exporting every instantiated member; ld64’s LTO drops weak explicit instantiations that nothing inside the dylib calls, so a library whose includers call members it never calls itself builds without LTO on macOS.T4 decidable No deduced return types on functions that are declared
externor used only through declarations: deducing the type instantiates the body.- Name:
template-no-deduced-returns
T4.1 decidable No deduced return types on overloads that differ only in their constraints (same name, parameters and qualifiers, told apart by their requires-clauses): write the return types out, or make them one function that branches with
if constexpr.- Name:
template-no-deduced-constrained-overloads
Taking the address of the overload set (
&T::f, as a binding’s member list does) deduces the return type of every overload, and so instantiates the bodies of those whose constraints fail too. AppleClang does not mangle requires-clauses (upstream clang does since 18;-fclang-abi-compat=17shows the old scheme), so those bodies share a symbol: in one TU the compiler rejects it (definition with same mangled name), across TUs the linker silently keeps either. runir’s role denotations ran their concept overload ofindices()on macOS this way. Overloads that differ in their parameters have symbols of their own, and member function templates constrained on their own template parameters drop out before their bodies are instantiated.T5 measured Split instantiating sources only along the dimension that drives their cost (family, task kind, context or constructor category) so no single TU dominates, even if the summed memory grows by the repeated includes.
- Name:
template-split-by-cost
Test a dimension by compiling the parts merged: if the merged source costs about as much as one part, the parts share their instantiations and the split only compiles them twice, so merge them as long as the merged source stays below the heaviest TU of the build. Tests split the same way: shared fixtures go to a
<test>_fixtures.hppheader, and the parts stay in one test executable. A split lowers the heaviest TU, but the peak build memory only if the heavy TUs no longer overlap: the parts fill the parallel slots. Keep a split only if the peak drops (identical builds vary by about 1 GB at -j12, so compare two runs each). Merge withbrokkr_unity_directories(<target> ENABLED ${<PROJECT>_UNITY_BUILD} DIRECTORIES ...): the sources of each directory listed compile as one TU, and<PROJECT>_UNITY_BUILD=OFFcompiles them apart again (for clang-tidy, and for rebuilds after editing one source). Light sources that include the same headers merge to about their largest part (type tests, bindings of one family). Merged heavy sources keep the summed memory down but can raise the peak at high parallelism, as more slots hold heavy TUs at once (the heaviest TU, and so the peak at low parallelism, stays): keep such a merge only where it buys wall time, and say so. A batch puts the file-local names of its sources into one TU: a name declared twice fails to compile (give each file a namespace of its own), but internal functions of one name and different parameters become overloads, and a call may resolve to another file’s; look for them before listing a directory (python -m pybrokkr.rules.template.unity_check --compile-commands <db> <directory>..., with the batches off), and rename them or give them their own namespace. Where a target’s heavy TUs still overlap, cap how many of them compile at once (brokkr_limit_compile_jobs(<target> JOBS <n>), a Ninja job pool): the other targets fill the free slots, so the peak drops at about the same wall time. The cap depends on the machine, so<n>is a cache variable set at configuration time, empty (no cap) by default.T6 judgment One container for many record types.
- Name:
template-one-container
Memo tables, visited sets and caches keyed by records of every type in a type list use one container keyed by (type position, index) instead of a tuple with one container per type: each container type instantiates its whole hash table. The key carries no dispatch; views are rebuilt from the index.
T7 decidable No all-types invocability constraints on internal visitors over long type lists.
- Name:
template-no-all-types-constraints
InvocableWithEach<F, List>(orstd::invocable<F, T>for eachT) on a generic lambda instantiates the lambda body for every type in the list, at every instantiation of the constrained function: a recursive visitor over N record types costs N x N body instantiations although each node visits only its few children. Constrain the public entry point if a diagnostic is wanted; leave internal helpers that only forward the visitor unconstrained.T8 judgment Dispatch your own types before a generic library’s trait-based dispatch.
- Name:
template-own-dispatch-first
boost::json::value_fromcomputes every conversion category (user, native, generic: sequence, map, tuple, optional, described class) of every nested type it converts, even when atag_invokeoverload matches. For types the library describes itself (yggdrasil’sdescribe_fields), and ranges and optionals of them, convert directly and hand only leaf types to the generic library. Types serialized as another object declareserialize_as(Dictionaries&, const T&)instead of a competingtag_invoke.T9 judgment Check compile-time contracts where the instantiation already exists.
- Name:
template-contracts-at-instantiation
A
static_assertover overload resolution against a heavy class (InternsData,rejects_symbolon a repository) instantiates that class. In a test that checks many repositories it re-instantiates all of them; in the library source that explicitly instantiates the repository it costs almost nothing. Put such contracts next to the explicit instantiation, with the shared contract concepts in adetailheader; tests keep the contracts on light types.T10 judgment Template on what the code depends on, not on what it passes along.
- Name:
template-no-forwarding-parameters
A parameter that only forwards to other templates multiplies every instantiation by its values and keeps the code out of the library. When the data is uniform (encoded bytes, indices) and only typed access needs the type, give the type its own identity (a constant of its codec or traits, not its position in a list) and keep the type list at the edges that turn a runtime type back into a value type. Once the parameter is gone, the code is no longer a template: move its definitions into the library (
T2), or every includer compiles them (I5). The parameter also deferred checking: expressions that no longer depend on a template parameter are checked where they are written, so they need complete types there (an include, a deduced parameter such as the repository type, or a library definition), and a recursive structure must define a type before the members that hold it by value.T11 measured Split storage templates into a read header and a write impl.
- Name:
template-read-write-split
When the write path of a widely included storage template (insertion, serialization) needs a dependency its read path does not, keep the class and the read API (
at,operator[],size, iteration, views) in<name>.hppand define the whole write API (insert*,create*,complete_miss*,append*,serialize) indetail/<name>_impl.hpp. Split along this boundary, not along the individual functions that need the dependency, and only when the measured difference is large. The class comment names the impl header. Sources with the explicit instantiation lists include the impl,<PROJECT>_HEADER_INSTANTIATIONbuilds include it in the#elsebranch of the extern list, and code that interns types nobody else instantiates adds explicit instantiations in one source. When a member only serves the write side (the value-to-index hash table of an interning set), declare its class in the header, define it in the impl and hold it by an owning raw pointer that the impl creates and deletes: the read header then never instantiates it. Not bystd::unique_ptrin a template instantiated per record type: it instantiatesunique_ptr,__uniq_ptr_impland astd::tuplefor every element type. Value lookup (find*), construction, destruction,clearand memory accounting go to the impl with it. A container keeps its element storage behind the same pointer, so reads and writes share one indirection; it holds by value only what inline reads need, a view of the storage (detail::SegmentedRows: the segment table’s and the size’s addresses), whose type does not depend on the storage template. Apply this in the containers only: their holders (repositories, tree sets) keep them by value. Define these members out of class: functions defined in the class body are implicitly inline, and an extern template declaration does not stop their instantiation in the includer.T12 judgment Keep
std::tupleandstd::unique_ptrout of per-type code.- Name:
template-no-tuple-per-type
A
std::tupleof N types instantiates N levels of_Tuple_impland the constraint traits of its constructors, andstd::unique_ptrstores its pointer in astd::tuple. In code instantiated for every record type or over long type lists, hold an owned object by raw pointer and keep the ownership in the out-of-class special members (T11), keep one object per type in flat bases (struct Slots : Slot<Ts>... {}, listed in reverse to keepstd::tuple’s destruction order: pooled objects may own handles into the pools of later types), and list record fields as member pointers (static constexpr auto cista_members() noexcept { return ygg::Members<&Data::index, &Data::a> {}; }; our cista fork folds over a staticcista_members()that returns such a pack) so that serialization, hashing, child visits andclear()fold over the pointers (ygg::for_each_member,ygg::clear_members) instead ofstd::tieandstd::apply. Acista_members()that returnsstd::tiein a non-template record compiles in every includer. Find such costs with clang’s-ftime-traceover the heaviest TUs, summed by template name.T13 judgment Compute once per value what depends on a value only.
- Name:
template-compute-per-value
A constant computed per template (a variable template, a static data member) is computed again for every template argument list, even where it depends on part of it only. Key it by that part, passed as a value: urd’s choice of a container depends on the request’s shape (what it requires, what its data is, what it holds), not on its element types, so
serving_for<Kind, Shape>scans the kind’s table once per shape, and every Store of that shape reuses the scan (74 shapes among 832 Stores in two pyrunir TUs). The value must be structural, as urd’sproperty_setis.T14 decidable Expand a pack instead of recursing over it.
- Name:
template-expand-packs
A recursion over a list is one class instantiation per step, each carrying every argument of the recursion; where one is a large value (a
property_setof 64 tags), naming and comparing it costs more than the step’s work. urd’s spec of a request takes the answer of each category of its kind’s format in one expansion (answers_of<Meant>(format): anmp_appendof each category’s answer, or of nothing), not in a recursion of one step per category for every Store.T15 decidable Build a
std::variantby its index.- Name:
template-variant-by-index
Its converting constructor resolves an overload set over all alternatives (
_Build_FUNs) for every type it is called with, so building each alternative of an N-way variant from a value resolves N sets of N.std::in_place_index<I>names the alternative instead. libstdc++ still builds alternative I through I nested unions (_Variadic_union), about N²/2 instantiations for a variant whose every alternative is built; a variant of many alternatives that is built often (a record’s variant of child views) is a cost of its own, which only a type of fewer alternatives, or none, removes.T16 judgment Define a recursion over every record kind once, at the records of any kind.
- Name:
template-recursion-at-any-kind
A visitor that recurses through a record’s children (an optimizer, a measure, a statistics collector) instantiates, from any one record, the closure of every kind below it; defined in a header, it makes every includer that calls it on one record compile all of them. Declare it in the header for the records of any kind, the variants that children are held as (a constructor of each category, a query of any kind): plain overloads, or explicit specializations of a member template, defined in the library. An includer then compiles the record it calls the visitor on and stops at its children. Move the non-template members that call the recursion out of the class too: their bodies instantiate it where the class ends, before the specializations are declared (ill-formed; clang rejects it, GCC does not). An inline non-template function in a header costs the same: every includer instantiates what it calls, whether or not it calls it.
T17 judgment Name a class whose definition is hidden by what it holds, not by its implementation.
- Name:
template-name-by-contents
Argument-dependent lookup of an unqualified call completes the class templates among the template arguments of its arguments’ types, to find their friends. A pimpl class
Repository<ConcurrentSymbolRepository<Ts...>, ...>therefore completes its stores in every file that passes one to an unqualified call: in tyr, one such call instantiated the 55 stores of a symbol repository. Named by empty descriptors of what it holds (Repository<ConcurrentSymbols<Ts...>, ConcurrentRelations<Tag, Ts...>>,yggdrasil/formalism/declarations.hpp), only those and the record tags complete, and the implementation maps them to its stores; in tyr this took a further 12 GiB (10%) off the summed peak memory of a full build. The same holds for any template argument that is costly to complete: a qualified call (detail::played_roles(...)) avoids the lookup where the type cannot change.
Process¶
T18 process Measure before and after.
- Name:
template-measure
Use the standalone cost of a header (
-fsyntax-onlyof a TU that only includes it), the cost of a single API call (the TU’s includes plus that call, at-fsyntax-onlyand at-O3), and a full instrumented build logging the max RSS per TU. GCC’s peak RSS also depends on when its garbage collector runs, which moves single TUs by up to about 200 MB without any change in live memory; check a surprising rise with--param ggc-min-expand=10 --param ggc-min-heapsize=32768before and after. Build each repository against a prefix that holds only the third-party dependencies and the freshly installed upstream repositories: the yggdrasil install bundles the prefix intopyyggdrasil/, whose include directory comes first, so a stale loki or tyr install there silently replaces the headers being measured.python -m pybrokkr.rules.template.compile_costrecords a build through CMake’s compiler launcher (-DCMAKE_CXX_COMPILER_LAUNCHER="python;-m;pybrokkr.rules.template.compile_cost;record;<log>": every object’s time and the compiler’s max RSS), summarizes a log and compares two by object. Sample the memory in use on the machine (MemAvailablein/proc/meminfo) during the build for its peak.compile_cost weak <build dir>sums the weak definitions of all objects by template: what the build compiles in more than one TU. A template that a library instantiates explicitly, found weak in another object, marks a TU that does that work without the opt-in list that declares it (T3); an extern list declared before its use keeps it out (an undefined symbol instead).T19 process Keep only what wins in the full build.
- Name:
template-keep-what-wins
A smaller standalone header often does not shrink its includers, which may instantiate the same code anyway. Revert changes that do not lower the max or summed memory of the affected TUs.
Examples¶
Rule |
Change |
Effect |
|---|---|---|
|
1.0 GB to 0.3 GB per includer (113 TUs) |
|
|
|
|
|
0.75 GB to 0.26 GB |
|
runir constructor and denotation repositories hold the tyr repository by pointer |
|
|
tyr statistics and heuristic tests include only the tested component |
2.5 GB to 2.0 GB per test TU |
|
pyrunir serialization bindings include their component’s type list and serializers instead of
|
20 DL, denotation and Uns bindings -0.9 to -1.0 GB, ps bindings -0.25 to -0.62 GB, identical symbols; pyrunir summed memory -20 GB, peak at -j12 29.6/31.0 GB to 27.8/26.8 GB, same wall time |
|
runir DL |
pyrunir DL semantics and feature bindings -0.5 to -0.67 GB each (4.6 GB to 4.1 GB), optimization test -0.12 GB; pyrunir summed memory -5 GB, peak at -j12 26.4/28.2 GB to 26.3/25.6 GB |
|
yggdrasil |
pyrunir |
|
runir constructor repository interning contracts moved from the DL family traits test into the nine
|
test 4.69 GB to 2.72 GB and 31 s to 17 s (the heaviest runir TU); repository sources +0 to +9 MB |
|
runir DL type tests’ view and data contracts (one per constructor type) probed in the repository source |
|
|
tyr planning |
tyr summed memory -24.5 GB (38 TUs up to -0.74 GB), runir -12 GB |
|
yggdrasil |
loki max TU 2.2 GB to 1.8 GB, tyr summed memory -4.6% |
|
yggdrasil |
loki max TU 1.80 GB to 1.70 GB; summed memory tyr -7.5 GB, runir -9.6 GB (query evaluation test 5.8 GB to 4.6 GB) |
|
runir |
8 TUs -57 to -113 MB |
|
runir DL evaluator compiled in eight library sources |
evaluating TUs -0.2 to -1.0 GB |
|
runir Ext evaluator with borrowed register values instantiated in the library instead of five tests |
test TUs -0.4 to -2.3 GB (max 7.5 GB to 5.3 GB), two new 2.8 GB sources |
|
runir Ext query evaluator over builder states instantiated in the library instead of a test |
successor expander test 4.5 GB to 4.0 GB, library source +44 MB; tests that pass their own callbacks to member
templates ( |
|
runir incremental |
|
|
runir projection heuristic calls |
|
|
runir Ext execution storage reads the entry module’s register counts from its data instead of a non-dependent
|
|
|
loki |
|
|
a standalone scan of all 1192 public headers (clang, one TU each) |
three headers did not compile on their own: tyr |
|
yggdrasil |
|
|
tyr headers that only take |
summed memory tyr 236.1 GB to 214.1 GB (TUs above 1 GiB 136 to 94), runir 256.4 GB to 237.5 GB (median 1.23 GB to
1.10 GB); 24 tyr TUs that create an |
|
cista fork: |
|
|
the TUs that grew with the row above (tyr search and heuristics +35 to +72 MB, runir
|
with frequent collections the same TUs are unchanged or lighter (gbfs_lazy 1206 MB to 1169 MB, program_executor 3276 MB to 3288 MB including its new explicit instantiations); the rise is GC timing |
|
gtl patch ( |
summed memory loki 82.8 GB to 77.5 GB (TUs above 1 GiB 11 to 5), tyr 206.4 GB to 188.4 GB (median 885 MB to 784 MB, above 1 GiB 90 to 70), runir 228.8 GB to 203.1 GB (max 3.89 GB to 3.40 GB, above 1 GiB 109 to 83); CPU -6 to -8%; no TU heavier |
|
records list their identifying members as member pointers,
|
tyr’s 107 records converted: summed memory 188.4 GB to 176.7 GB, median 784 MB to 701 MB, CPU -5%; one TU +36 MB |
|
yggdrasil |
summed memory loki 74.9 GB to 70.1 GB, tyr 180.3 GB to 156.5 GB (above 1 GiB 67 to 50, max 1.95 GB to 1.70 GB, median 565 MB to 483 MB), runir 198.1 GB to 169.2 GB (above 1 GiB 76 to 59, max 3.19 GB to 2.79 GB), yggdrasil 58.8 GB to 57.7 GB; CPU -4 to -16%; changes the container layout, so prebuilt downstream packages must be rebuilt |
|
yggdrasil |
summed memory loki 69.0 GB to 65.8 GB (above 1 GiB 3 to 1), tyr 152.5 GB to 141.1 GB (median 579 MB to 525 MB, above 1 GiB 46 to 30, max 1.66 GB to 1.54 GB), runir 164.5 GB to 143.8 GB (median 672 MB to 545 MB, above 1 GiB 60 to 48), yggdrasil 53.2 GB to 52.8 GB; peak at -j32 tyr 41.6 GB to 37.5 GB; CPU -4 to -9%; no TU more than 20 MB heavier |
|
runir |
a TU that creates a repository 2.27 GB to 0.78 GB; with the projection change: 49 runir TUs -50 MB to -0.6 GB, summed -13.3 GB, none heavier than +6 MB |
|
runir |
callers no longer construct or destroy the symbol pools; needed for the macOS link of the incremental query test |
|
runir CNF translation asserted |
completed the repository type in Debug builds only (GCC 13 CI error); compares |
|
runir on macOS: ld64 LTO dropped the denotation and query pool members that only tests call through the opt-in extern lists |
runir skips LTO on Apple; Linux keeps it |
|
runir Uns parser includes extern declarations of the Uns symbol storage |
3.95 GB to 2.89 GB |
|
runir optimization, query evaluation and successor expander tests include the lists of the families they intern |
-0.3 to -0.5 GB per TU; the same lists cost +0.1 to +0.7 GB in TUs that only evaluate |
|
pyrunir bindings that intern or evaluate include their family’s lists and the denotation list |
24 binding TUs -0.2 to -1.5 GB, summed pyrunir memory -22 GB; the lists cost up to +0.4 GB in bindings that only wrap views |
|
runir grammar and CNF grammar lists dropped, then restored |
link -56 s and wall 379 s to 342 s, but peak at -j12 26.1 GB to 28.5 GB; restored because peak memory limits the build |
|
second runir sweep over all TUs above 1.4 GB without lists |
ten more TUs -65 to -534 MB (domain_context, parser, structural termination, classifier and executor tests); none between 1.4 and 2 GB gained more than 100 MB |
|
tyr applicability, serialization and datalog solver tests split along task kind and test groups |
3.05-3.3 GB to at most 2.95 GB |
|
the runir optimization test split by task kind |
no change (7.1 GB per half); the cost depends on the family |
|
runir DL evaluator and incremental engine merged from 16 sources (family x kind x context) into one per family |
2.8-3.6 GB per part, 3.5-4.0 GB per family; summed build memory 334 GB to 299 GB, wall 403 s to 370 s |
|
runir program executor data headers without the proof graph and plan definitions |
1.4 GB to 0.5 GB on their own, no change in the build: every includer uses the graph; reverted |
|
runir DL and ps optimizers memoize in one map instead of one per record type |
optimization test 6.4 GB to 4.2 GB; pyrunir bindings that optimize -1.1 to -3.0 GB each (max 8.8 GB to 5.8 GB) |
|
runir |
evaluating library sources -38 to -54 MB (1.5%): the query and join-index caches dominate the class; tests check per-category entries, which one map can answer only with extra counters on the hot path; reverted |
|
yggdrasil |
summed memory +0.1 GB loki, +1.2 GB tyr, +0.8 GB runir: few TUs use the relation storage; reverted |
|
runir |
|
|
yggdrasil |
tyr summed memory +7.9 GB (123 TUs heavier, max 2.80 GB to 2.64 GB), runir +4.4 GB, opt-in sweep +0.2 to +1.3 GB in every heavy runir TU: the extern class instantiates every pool; reverted |
|
runir DL grammar parser instantiations split by family |
4.2 GB, 64 s to 2.5-2.8 GB, 25-28 s per family; summed memory +3.7 GB |
|
runir symbol storage instantiated member by member (only out-of-class members) to shorten the library LTO link |
link 240 s to 225 s, but tests failed to link: inline members such as |
|
runir |
|
|
runir DL optimizer behind a pointer and compiled once per family in the library ( |
pyrunir summed memory -18 GB and TUs above 3 GiB 37 to 20, but peak at -j12 runir 26.4 GB to 28.9 GB, pyrunir 28.6 GB to 29.4 GB; reverted |
|
the same with each family’s source split into optimizer and statistics halves ( |
runir peak 26.6 GB to 26.9 GB and wall 333 s to 359 s, pyrunir peak 28.6 GB to 30.0 GB; reverted: new library sources raise the peak while other heavy TUs compile |
|
runir family traits, query evaluation and query allocation tests split along their test groups |
heaviest TU 4.7 GB to 4.2 GB, but peak at -j12 24.6/26.0 GB before and 25.7/26.4 GB after, same wall time; reverted |
|
runir symbol storage sources kept per repository and family |
merging three costs as much as the parts (44-57 s, 4-5 GB) |
|
yggdrasil database engine without the |
query test 2.41 GB to 1.55 GB and 34 s to 18 s (it instantiated the engine for three lists), other database TUs
-8% to +44%: median 622 MB to 879 MB, headers on their own 0.45-0.65 GB to 0.57-0.95 GB, since the now
non-template inline code compiles in every includer ( |
|
the same engine compiled once in |
36 database TUs: max 2.41 GB to 1.23 GB, above 1 GiB 8 to 3, summed 29.8 GB to 25.1 GB, wall 371 s to 246 s; the library adds 26 sources (12.7 GB, max 0.88 GB), and test builds a second, instrumented copy for the two work-counting tests (another 12.7 GB) |
|
28 non-template member functions of 8 lines or more (search, generic join, plans, cost model) defined out of class in the library; codecs and row accessors stay inline for the hot paths |
database TUs summed 25.1 GB to 24.6 GB, max 1.23 GB to 1.15 GB, but 7 more library sources at about 0.5 GB each: library 12.7 GB to 16.3 GB |
|
the 33 |
library 16.3 GB to 3.8 GB, 140 s to 39 s, heaviest 1.0 GB; with the previous rows the whole yggdrasil build goes from 61.8 GB summed, max 2.41 GB, 9 TUs above 1 GiB, 67 s at -j16 to 59.7 GB, 1.15 GB, 2, 45 s |
|
the shared |
incremental distance with dense ties 5.5 µs (header-only) to 12.1 µs (library) back to 4.7 µs: without it,
|
|
yggdrasil |
summed memory tyr 141.1 GB to 138.7 GB (above 1 GiB 30 to 28), runir 143.8 GB to 142.3 GB, loki and yggdrasil -0.3%; peak at -j32 tyr 37.5 GB to 35.6 GB, runir 67.3 GB to 64.0 GB; CPU +2 to +3% in tyr and runir in two runs |
|
records return their fields from a static |
summed memory yggdrasil 52.6 GB to 50.6 GB, loki 65.5 GB to 60.6 GB (median 346 MB to 308 MB), tyr 138.7 GB to 128.8 GB (median 509 MB to 480 MB, above 1 GiB 28 to 21, max 1.51 GB to 1.42 GB), runir 142.3 GB to 129.1 GB (median 541 MB to 507 MB, above 1 GiB 47 to 41); CPU -4 to -12%; peak at -j32 loki 16.6 GB to 14.4 GB, tyr 35.6 GB to 32.3 GB; one TU +33 MB |
|
tyr planning and datalog |
summed memory tyr 128.8 GB to 123.5 GB (median 479 MB to 438 MB, above 1 GiB 21 to 18), runir 129.1 GB to 127.1 GB (median 507 MB to 490 MB); one TU +27 MB |
|
cista |
no change in any repository (-0.1% to +0.1%); clang traces had already put it at about 1% of runir’s front end; reverted |
|
runir DL grammar |
base 2.40 GB to 1.68 GB, ext 2.57 GB to 1.83 GB, uns 2.69 GB to 1.94 GB, 34-38 s to 15-18 s each; runir summed 127.1 GB to 124.9 GB, max 2.68 GB to 2.21 GB, peak at -j32 60.9 GB to 56.2 GB |
|
runir |
halves 1.62-1.80 GB against 2.00-2.21 GB, runir max 2.21 GB to 1.94 GB, but summed 124.9 GB to 128.7 GB, CPU +3%, peak at -j32 56.2/62.9/62.9 GB to 69.3/66.5/62.7 GB in three runs each; reverted |
|
tyr |
lmcut 1.35 GB to 1.06 + 1.25 GB, rpg_ff 1.25 GB to 0.99 + 1.17 GB: the lifted half keeps 90-95%, so the max drops about 0.1 GB for about 1 GB more summed memory; not applied |
|
yggdrasil |
|
|
runir: sketches and classifiers moved to the Ext DL constructor set (made the union of all three), a capability check per language in the shared AST translation, then the Base and Uns DL instantiations (evaluation, symbol storage, Spirit rules, AST parsers) and the Ext and Uns grammar and CNF storage deleted |
runir summed 123.8 GB to 107.6 GB, CPU 22.1 to 18.6 min, wall 94 s to 69 s, peak at -j32 58.4 GB to 35.9 GB, largest link 2.31 GB to 1.18 GB |
|
runir DL |
first version 107.6 GB to 109.6 GB: generation grammar and CNF types took the union constructor set (their symbol storage sources +0.32 GB each), and the query translator, query construction and others became non-template code in headers; generation grammars back on the Base set 108.2 GB; translator and query construction defined in the library 108.1 GB, max 2.13 GB, peak at -j32 33.3 GB, wall 69 s; with the renames 108.1 GB, peak 30.0 GB |
|
yggdrasil |
summed memory tyr 123.5 GB to 119.2 GB (median 437 MB to 409 MB, above 1 GiB 16 to 15), runir 107.9 GB to 105.0 GB (median 426 MB to 403 MB), loki 60.5 GB to 60.0 GB; largest drops 0.07 GB (tyr) and 0.10 GB (runir); tyr A* blind and FF on 27 HTG tasks, lifted and ground: identical expansions and costs, stable cases within 5%, peak RSS geomean 0.98 to 1.005 |
|
the runir build with its tests and pyrunir (255 TUs; GCC 13, Release, -j12) measured again after urd took over the containers, records and graphs, against the rows above |
summed memory 381.4 GB, median 1236 MB, max 4.08 GB, CPU 79.5 min, wall 427 s, peak 38.4 GB; clang traces of the heaviest TUs put urd’s own templates at 26% of their instantiation time and constant evaluation at 6%, most of it choosing containers (the rows below) |
|
urd |
front end (-fsyntax-only, frequent collections): DL repository 9.6 s to 8.4 s and 1.86 GB to 1.62 GB, DL evaluation 25.2 s to 20.9 s, successor expander test 29.9 s to 25.9 s; with the next row, the runir build CPU 79.5 min to 70.8 min, summed memory 381.4 GB to 358.4 GB, max 4.08 GB to 3.92 GB, wall 427 s to 380 s |
|
urd’s |
20 to 30 MB per TU; the variants’ |
|
urd |
front end -66 to -177 MB and -0.4 to -1.6 s per TU (DL repository 1.62 GB to 1.56 GB, successor expander test 3.13 GB to 2.95 GB) |
|
runir |
with the previous row, runir CPU 70.8 min to 65.6 min, summed memory 358.4 GB to 329.8 GB, max 3.92 GB to 3.65 GB, median 1120 MB to 1020 MB, slowest TU 95 s to 63 s, wall 380 s to 356 s, peak 37.8 GB to 36.9 GB; tyr (only the urd rows) CPU 36.8 min to 32.2 min, summed 222.7 GB to 200.3 GB, median 874 MB to 780 MB, above 1 GiB 97 to 66, wall 205 s to 181 s, peak 26.1 GB to 25.4 GB |
|
TUs that intern without the opt-in list of what they intern, found as weak |
at -O3: CNF generation 61.8 s to 44.6 s and 3.06 GB to 2.57 GB, query evaluation test 64.4 s to 55.2 s, tyr static rule filter 21.2 s to 15.0 s and 1.22 GB to 0.97 GB, rule splitting 23.3 s to 16.6 s; the ps Ext program executor binding was unchanged and keeps no list |
|
pyrunir’s sources of one directory compiled as one TU ( |
runir 256 TUs to 190, CPU 64.8 min to 56.1 min, summed memory 328.7 GB to 271.6 GB, wall 350 s to 305 s, max 3.58 GB to 3.62 GB, peak 36.5/36.6 GB to 37.7/38.0 GB (two runs each); tyr 262 TUs to 224, CPU 31.4 min to 28.2 min, summed 197.7 GB to 174.3 GB, wall 176 s to 161 s, peak 25.8 GB to 23.6 GB |
|
tyr’s library ( |
tyr 224 TUs to 160, CPU 28.2 min to 21.8 min, summed memory 174.3 GB to 128.0 GB, wall 161 s to 130 s, max 2.12 GB, peak 23.6 GB to 23.9 GB; with the rows above, tyr CPU 36.8 min to 21.8 min, summed 222.7 GB to 128.0 GB, wall 205 s to 130 s, peak 26.1 GB to 23.9 GB |
|
pytyr batched: |
tyr with pytyr: library 121 TUs to 57 (106.5 GB to 60.1 GB summed), pytyr 86 TUs to 29 (73.6 GB to 42.0 GB), CPU 27.8 min to 17.4 min, wall 158 s to 104 s, max 2.99 GB, but peak at -j12 25.3/25.5 GB to 27.6/27.6 GB; the job pool below brings the peak back down |
|
tyr’s |
|
|
the Python modules’ TUs compiled at most 6 at once ( |
runir peak at -j12 38.0/38.4 GB to 34.1/34.2 GB, wall 310 s to 312/308 s (4 at once: 385 s, 35.9 GB); tyr with pytyr 27.6/27.6 GB to 24.6/23.8 GB, wall 104 s to 114/115 s; with all rows above, tyr with pytyr CPU 27.7 min to 14.2 min, summed 180.0 GB to 91.3 GB, wall 158 s to 114 s, peak 25.4 GB to 24.2 GB; runir CPU 79.5 min to 55.5 min, summed 381.4 GB to 271.6 GB, max 4.08 GB to 3.62 GB, wall 427 s to 308-314 s, peak 38.4 GB to 34.1/34.2/37.0 GB in three runs (the third after reinstalling tyr) |
|
runir’s library ( |
sixteen: summed 271.6 GB to 254.0 GB, CPU -2.2 min, but peak 37.0/38.0 GB to 38.9/40.2 GB; eleven: summed -7.6 GB, wall unchanged, peak 38.9/38.3 GB; not applied: batches of 2.5 GB and more compile at once what ran apart, and runir’s library holds the build’s heaviest sources |
|
pyrunir sources batched in name order, two or three per directory, and whole directories whose sources share
little ( |
batches of three: max 5.09 GB, peak 41.7 GB; of two: 43.0 GB ( |
|
urd |
no change (at most 0.6 s and 20 MB per TU in either): code compiled in many TUs is not the cost where the front end decides; reverted, and fmt kept header-only |
|
runir’s query optimizer and query statistics collector: their entry points for a constructor of each category
and a query of any kind as explicit specializations, defined with the non-template members (the maximal-query
optimization, the rewrites of must-pass, distance and nonempty records) in |
runir summed memory 271.6 GB to 263.6 GB, CPU 55.5 to 53.3 min, slowest TU 76 s to 71 s, wall 314 s to 288 s, peak 34.1-37.0 GB to 32.5 GB; the optimizer’s includers -0.3 to -1.0 GB each (its test 3.0 GB to 2.0 GB) |
|
pyrunir’s serialization: writing a constructor of each category or a query of any kind ( |
the eleven serialization TUs -0.2 to -0.6 GB each, summed 263.6 GB to 259.7 GB, wall 278 s, peak 33.6 GB |
|
tyr’s public |
runir’s DL binding TUs -0.1 to -0.2 GB, summed 259.7 GB to 258.2 GB, peak 31.6 GB, wall 278 s; with all rows above, runir CPU 79.5 to 51.6 min, summed 381.4 GB to 258.2 GB, max 4.08 GB to 3.52 GB, wall 427 s to 278 s, peak 38.4 GB to 31.6 GB |
|
tyr’s |
runir summed 258.2 GB to 247.6 GB, median 1216 MB to 1143 MB, max 3.52 GB to 3.41 GB, CPU 51.6 to 50.5 min, wall 278 s to 270/272 s, peak 31.6 GB to 31.9/31.8 GB (two runs); tyr with pytyr summed 91.1 GB to 89.9 GB, max 2.99 GB to 2.83 GB, wall 114 s to 112 s, peak 22.0 GB to 22.4 GB; with all rows above, runir CPU 79.5 to 50.5 min, summed 381.4 GB to 247.6 GB, max 4.08 GB to 3.41 GB, wall 427 s to 270 s, peak 38.4 GB to 31.8 GB; tyr with pytyr CPU 27.7 to 13.9 min, summed 180.0 GB to 89.9 GB, wall 158 s to 112 s, peak 25.4 GB to 22.4 GB |
|
precompiled headers (GCC, the headers 42 of 50 pyrunir TUs share); GCC’s collector run more often
( |
precompiled: 33.7 s to 32.4 s, 3.42 GB to 3.44 GB (the headers parse in 5 s, the TU’s instantiations dominate); collector at 50: -8% memory, +8% time, at 20: -14%, +34%; neither applied |
|
urd’s facts of a role: the traits a kind asks of the role filtered once per kind and role
( |
clang -5% on a TU that completes runir’s DL repository, GCC unchanged (3.38 s to 3.37 s, same memory); reverted: GCC builds the libraries |
|
runir compiled with clang 18 instead of GCC 13 (the same flags, LTO off; after rewriting one generic visitor
lambda in |
runir: summed memory 247.6 GB to 193.6 GB, median 1143 MB to 894 MB, max 3.41 GB to 2.50 GB, CPU 50.6 to 52.6 min, wall 270 s to 284 s, peak at -j12 31.8 GB to 21.8 GB; tyr: summed 113.9 GB to 90.5 GB, max 2.10 GB to 1.60 GB, CPU 19.8 to 21.7 min, wall 117 s to 144 s, peak 23.7 GB to 17.9 GB; tests pass (27, 49) and run as fast (tyr’s, one at a time, 196 s to 175 s; runir’s 5.7 s to 6.0 s); not applied: a choice of toolchain, not of code |
|
where a Store’s 2.15 MB (GCC, completing it) goes, over 120 Stores of sets, sequences and maps of distinct element types, each part switched off in turn in a copy of urd: the choice of the container, its completion, the facets’ conditions and each facet |
choosing 0.8 MB (the element types’ traits), the container 0.4 MB, the facets’ conditions 0.15 MB, the facets 0.6 MB spread over about fifteen (at most 3 MB over 120 Stores for any one), the Store’s own members the rest; constructing one adds 0.4 MB; no part to remove alone: only fewer Stores per TU, or a different design, would shrink it |