Spokes.wiki Search About
Defined Term updated Wed Jul 15 2026 00:00:00 GMT+0000 (Coordinated Universal Time)

Monomorphization (specialized-parser codegen)

Generating type-specialized code for one concrete shape instead of running a single generic routine that dispatches on type at runtime. In a JIT-compiled host (V8/JS), the generic version accumulates megamorphic call sites — one call site sees many types, so the engine can’t inline it — which is the dominant cost of a data-shape-agnostic parser. Emitting a parser tailored to exact types turns those into monomorphic sites the optimizer can inline end-to-end. The performance lever behind clickhouse-rowbinary.

The move

  • Read the schema/type list once, at generation time.
  • Emit straight-line reads in the correct sequence — constant offsets, one bounds check per row instead of per field, zero runtime type dispatch (a composed reader with per-field checks collapses to, e.g., a single 26-byte row check + fixed-offset reads).
  • Pay the specialization cost once (here, an AI agent generates the code from densely-commented primitives via a SKILL.md — the “parser compiler” framing), then run the inlinable result hot.

Where it sits among the spoke’s performance levers

synthesis tracks how each source wins performance by removing a different layer of overhead. Monomorphization is a distinct lever from the others:

  • Language porttypescript-7-go-compiler (TS→Go, native code).
  • Data layoutflat-ast / yaff (contiguous, indices-not-pointers; drop the parse/allocation cost). Monomorphization is the layout discipline’s control-flow sibling: flat-ast removes pointer-chasing, monomorphization removes type-dispatch.
  • Incremental optimizationgit 2.55-style tuning of the incumbent.
  • Specialization / codegenthis: generate narrow code for a known shape so the JIT can inline it. The novelty in clickhouse-rowbinary is who does the specializing — an LLM agent, not a schema compiler.

clickhouse-rowbinary · flat-ast · yaff · developer-tooling · synthesis