Skip to content

Profile and root-cause 101 MiB Debug object-file and compile-time explosion on wrapper-annotated structs #90

Done

Description

@clockblocker

Question

What exact template instantiations, symbol/DWARF emissions, and reflect-cpp metaprogramming paths cause a 48-field wrapper-annotated struct to explode into a 101 MiB Debug .o file and ~35s compile time, and where are the highest-leverage levers to cut both by an order of magnitude?

Evidence & Context

  • Parent map: Map (Lane 1): Core Hygiene & Perf
  • ccache#2: config.cpp.o = 106.25 MB (~101 MiB) and ~35s Debug compile on 48-field ConfigData annotated with rfl::Description<StringLiteral, ...>.
  • cppcheck#3: 37-field ProjectFileSchema compiled across 5 pipelines.
  • osmium-tool#3: 20–30 CPU-s/TU across 23 subcommand TUs.

Execution Notes

  • Hold timing runs until heavy local builds clear so -ftime-trace and wall-clock measurements are not skewed by CPU/IO contention.
  • Produce concrete -ftime-trace flamegraph breakdowns, nm/bloaty/DWARF section attributions on ccache#2 config.cpp.o, and a ranked list of root causes (e.g., StringLiteral NTTP mangling length, nested wrapper tuple/visitor instantiation depth, DWARF debug-info duplication) to unblock the Lane 1 zero-bloat prototype ticket.

Activity

  1. added
    wayfinder:research
    on Nov 27, 2026
  2. clockblocker commented on Nov 27, 2026

    @clockblocker
    OwnerAuthor

    Additional Showcase Evidence (clockblocker/transmission#1, 6478ae0d0):

    • Large plain reflected structs in transmission/libtransmission/rpc-schema.h — TorrentInfo (81 fields) and SessionSetParams (53 fields) — incur ~25–59s user compile time per RPC TU on AppleClang arm64 RelWithDebInfo.
    • This confirms the compile-time cliff reproduces even in RelWithDebInfo on large 50–80+ field structs (not only wrapper-heavy Debug builds), directly validating upstream #799 / Wave 10 #61. Include transmission/libtransmission/rpc-schema.h in -ftime-trace profiling alongside ccache#2 config.cpp.o.
  3. clockblocker commented on Nov 27, 2026

    @clockblocker
    OwnerAuthor

    Recipient update: ccache has been retired as a Showcase Migration recipient (fork being deleted). Reproduce the 48-field rfl::Description<StringLiteral, DefaultVal<T>> 101 MiB Debug .o cliff using a self-contained in-repo repro under reflect-cpp/bench/, paired with real-world measurements from transmission#1 (81-field TorrentInfo / 53-field SessionSetParams), osmium-tool#3, and slang-server.

  4. clockblocker commented on Nov 27, 2026

    @clockblocker
    OwnerAuthor

    Active Regression Harness Evidence (clockblocker/slang-server#1, bf857f4 — all-planned-prs 7a8ab835 vs upstream a26047a, AppleClang 17 arm64 RelWithDebInfo):

    • Compile-time regression across all-planned-prs:
      • slang_server_obj_lib (41 TUs CPU sum): 389.25s → 599.47s (base) / 590.76s (final, +51.8%)
      • SlangServer.cpp.o: 121.18s → 217.09s (base) / 177.60s (after rfl::json::Raw, +46.6%)
      • reflectcpp_json.cpp.o: 19.38s → 30.18s (base) / 32.00s (final, +65.1%)
    • Schema binary bloat (src/gen_config_main.cpp:16-18):
      • bin/gen_config_schema: 1.38 MiB (1,446,752 B) → 1.70 MiB (1,781,456 B) (+335 KB / +23.1%) even after deleting addDefaults/rfl::Generic, driven by per-field to_generic instantiation across $defs under to_schema<T, rfl::DefaultIfMissing>.
    • (Note: bin/slang-server itself shrank 14.65 MiB → 13.91 MiB / −5.06%.)
    • Prioritize profiling SlangServer.cpp.o, reflectcpp_json.cpp.o, and gen_config_schema alongside ccache#2 / transmission#1 since slang-server is an active regression harness.
  5. clockblocker commented on Nov 27, 2026

    @clockblocker
    OwnerAuthor

    Completed -ftime-trace, Mach-O size -m, and nm symbol profiling on a quiet AppleClang 17 arm64 host against showcase/all-lanes (49f044ec). Unblocks #91.

    1. Self-Contained 48-Field ConfigData Repro (rfl::Description<StringLiteral, DefaultVal<T>> vs Plain + DefaultIfMissing)

    Repro (48 fields: read + write + to_schema) Mode Wall .o Size __DWARF,__debug_str sum(len(mangled)) __TEXT,__text Max Mangled Symbol
    bench_48_desc (Description<StringLiteral, DefaultVal<T>>) Debug (-O0 -g) 6.68s 148.70 MiB 82.65 MiB (55.6%) 62.77 MiB (42.2%) 0.65 MiB (0.4%) 43,854 chars
    bench_48_plain (plain fields + DefaultIfMissing) Debug (-O0 -g) 3.24s 19.11 MiB 10.19 MiB (53.3%) 6.62 MiB (34.6%) 0.45 MiB (2.3%) 11,026 chars
    bench_48_desc (Description<StringLiteral, DefaultVal<T>>) RelWithDebInfo (-O2 -g) 9.13s 48.25 MiB 35.40 MiB (73.4%) 10.10 MiB (20.9%) 0.15 MiB (0.3%) 43,724 chars
    bench_48_plain (plain fields + DefaultIfMissing) RelWithDebInfo (-O2 -g) 4.64s 8.04 MiB 4.80 MiB (59.7%) 1.28 MiB (15.9%) 0.12 MiB (1.4%) 10,899 chars

    Mangled symbol breakdown on bench_48_desc Debug (8,754 symbols, 62.77 MiB):

    • Tuple: 17.39 MiB (802 syms)
    • NamedTupleParser: 14.03 MiB (357 syms)
    • NamedTuple: 13.66 MiB (357 syms)
    • Parser: 12.00 MiB (646 syms)
    • ViewReader: 3.92 MiB (102 syms — dead instantiation!)
    • ViewReaderWithDefault: 2.34 MiB (61 syms)

    2. Active Regression Harness: slang-server (RelWithDebInfo -O2 -g, showcase/all-lanes)

    TU Wall Frontend / Backend .o Size __debug_str __text Top -ftime-trace Hotspots
    SlangServer.cpp 39.44s 19.58s / 19.59s 60.58 MiB 36.01 MiB (59.4%) 0.99 MiB (1.6%) ViewReader 40.57s (973x), NamedTupleParser 39.82s (1302x), Parser 38.85s (1312x), ModuleInlinerWrapperPass 9.73s, CountFieldsHelper 7.62s (1817x)
    reflectcpp_json.cpp 8.73s 3.88s / 4.78s 12.09 MiB 7.61 MiB (62.9%) 0.24 MiB (2.0%) Parser 10.51s, NamedTupleParser 4.54s, Variant 4.12s, ModuleInlinerWrapperPass 2.67s
    Config.cpp 5.58s 3.16s / 2.34s 13.01 MiB 9.75 MiB (74.9%) 0.13 MiB (1.0%) Parser 2.66s, ViewReaderWithDefault 2.20s (312x), NamedTupleParser 2.02s
    gen_config_main.cpp 3.86s 2.38s / 1.42s 9.46 MiB 7.04 MiB (74.4%) 0.08 MiB (0.9%) Parser 3.66s, NamedTupleParser 1.83s, to_generic / generic::write 29x instantiations across $defs

    3. Ranked Root Causes & Levers for #91

    1. Long StringLiteral<N> NTTP mangling baked into field types (rfl::Description<"...", DefaultVal<T>>) — 7.8× Debug .o bloat (129.6 MiB) & 2.1× compile time: Every byte of prose mangles as a separate decimal char literal (~4–5× expansion) inside NamedTuple<48 fields>, creating 43 KB mangled names repeated across thousands of symbols (97.8% of .o is __debug_str + symbol table; only 0.4% is __text). Lever: Out-of-band zero-bloat metadata specialization (rfl::Metadata<T>) keeping prose completely out of field C++ types.
    2. Per-field member function templates on NamedTupleParser<..., 48 fields> and ViewReader<..., 48 fields> (and linear fold-expression dispatch in ViewReader) — drives BOTH bench_48_plain (19.1 MiB) and SlangServer.cpp (39.4s / 60.6 MiB): add_field_to_object<0..N-1>, add_field_to_schema<0..N-1>, handle_one_missing_field<0..N-1>, and ViewReader::assign_if_field_matches<0..N-1> each repeat the full NamedTuple mangled type, and ViewReader's inline fold expression hammers LLVM's ModuleInlinerWrapperPass (9.73s on SlangServer.cpp). Lever: Move per-field work to non-nested free helpers parameterized only by (R, W, CoreType, ProcessorsType) and give ViewReader sorted binary-search table dispatch.
    3. Linear $O(N^2)$ CountFieldsHelper::count_max_args_in_agg_init (num_fields.hpp:109-117) — 7.62s (1,817×) in SlangServer.cpp & 1.30s in bench_48_desc: Scans n = 0, 1, 2, ..., N one by one instead of exponential + binary search once constructible<lo>() succeeds (which holds at lo = 0 for almost all structs).
    4. Per-field rfl::to_generic<ProcessorsType> instantiation in NamedTupleParser::add_field_to_schema under DefaultIfMissing — +23.1% gen_config_schema binary bloat (29× instantiations): Fast-pathing basic scalars directly to rfl::Generic(...) avoids instantiating generic::Writer per scalar field.
    5. Dead ViewReader instantiation in read_struct_with_default (Parser_default.hpp:1170) when DefaultVal is wrapped in Description: Adds 1.41s + 3.92 MiB of dead ViewReader symbols to bench_48_desc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    wayfinder:research

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions