Module: Lutaml::Xml::PlanCompiler

Defined in:
lib/lutaml/xml/plan_compiler.rb

Overview

Phase 5 slice: compile a model's XML mapping into a Leptris::XML::Descriptor plan and materialize whole documents in one native pass (leptris_plan_walk) — no moxml wrapper tree, no per-element Ruby dispatch. Measured on the 200-item probe: walk+hydrate 8.7x faster, 82% fewer allocations than the interpretive path, hydration-equal output.

A model compiles only when EVERY rule is plan-shaped; anything richer keeps the interpretive path (all-or-nothing per model):

- map_attribute / map_element rows only
- element rows: Value-scalar types or nested Serializables
- no content/raw mappings, custom methods, delegates,
polymorphism, transforms, multiple spellings, namespaces,
ordered mappings, hash_mappings, root_mappings
- attributes not derived/union/polymorphic

The fast path is opt-in (Config.xml_plan_fast_path) while the full semantics audit (parent links, consolidation, ordering metadata) completes.

Constant Summary collapse

PLAN_CACHE =

Isolated holder: suites freeze model classes; a cache on a frozen constant would be immutable (TypeProbeCache precedent).

::Class.new do
  class << self
    def cache
      @cache ||= {}
    end
  end
end.cache

Class Method Summary collapse

Class Method Details

.compile(model_class, register) ⇒ Object



36
37
38
39
40
41
# File 'lib/lutaml/xml/plan_compiler.rb', line 36

def compile(model_class, register)
  key = [model_class, register]
  return PLAN_CACHE[key] if PLAN_CACHE.key?(key)

  PLAN_CACHE[key] = build(model_class, register)
end