Top Level Namespace

Defined Under Namespace

Modules: Lutaml, PerformanceHelpers, XmlCompilerBenchmarks, YAML Classes: Address, BenchmarkRunner, CollectionHandlerBenchmark, Module, PerformanceComparator, Person, SomeCollection, WeakRef, XmlCompilerBenchmarkRunner, XmlElementBenchmark

Constant Summary collapse

ITERATIONS =

Number of iterations for profiling

10
REPO_ROOT =
Pathname.new(File.expand_path("../../..", __dir__))
LIB =
REPO_ROOT.join("lib")
NATIVE_ONLY_PATTERNS =

Patterns excluded under Opal because they pull in native-only deps (Nokogiri/Ox C extensions, Thor CLI, etc.). REXML is pure Ruby and ships in the bundled gem + moxml's lib/compat/opal/rexml/* shadows, so it is NOT excluded — it is a fully working second Opal adapter.

[
  %r{(nokogiri|ox)_adapter\z},
  %r{/schema/(relaxng|xsd)\b},
  %r{/schema_builder/(nokogiri|oga)\b},
  %r{/schema/builder/(nokogiri|oga)\b},
  %r{\Alutaml/model/cli\z},
].freeze
DECL_RE =

Match autoload :Name, "...anything..." where the string argument may span multiple physical lines (whitespace after the comma).

/autoload\s+:[A-Za-z0-9_]+\s*,\s*"([^"]+)"/
ENTRY_FILES =

Order matters: namespace-defining entry files must load before any of their nested files. lutaml/model.rb declares the Lutaml::Model module (referenced by every other file); lutaml/xml.rb declares Lutaml::Xml. After the entry files, load by depth-then-name so a parent file (e.g. lutaml/hash_format.rb) is required before its children (e.g. lutaml/hash_format/adapter/document.rb).

ENTRY_FILES are added unconditionally: they are top-level entry points that nothing else autoloads (because they ARE the entry points users require directly), so they would otherwise be missing from the list.

%w[lutaml/model lutaml/xml].freeze

Instance Method Summary collapse

Instance Method Details

#join_multiline_autoloads(src) ⇒ Object

Stitches multi-line autoload declarations into a single logical line so DECL_RE can match. We only merge when the line ends right after the comma that follows autoload :Name.



40
41
42
# File 'lib/compat/opal/generate_boot.rb', line 40

def join_multiline_autoloads(src)
  src.gsub(/(autoload\s+:[A-Za-z0-9_]+\s*,)\s*\n\s*/) { "#{Regexp.last_match(1)} " }
end

#person_instanceObject



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/tasks/memory_profile.rb', line 74

def person_instance
  Person.new(
    id: 123,
    first_name: "John",
    last_name: "Doe",
    email: "john@example.com",
    age: 30,
    address: Address.new(
      street: "123 Main St",
      city: "City",
      zip: "12345",
      country: "Country",
    ),
    phone_numbers: ["555-1000", "555-2000"],
    tags: ["tag1", "tag2"],
  )
end

#person_xmlObject

Test data



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/tasks/memory_profile.rb', line 53

def person_xml
  <<~XML
    <person id="123">
      <first_name>John</first_name>
      <last_name>Doe</last_name>
      <email>john@example.com</email>
      <age>30</age>
      <address>
        <street>123 Main St</street>
        <city>City</city>
        <zip>12345</zip>
        <country>Country</country>
      </address>
      <phone_number>555-1000</phone_number>
      <phone_number>555-2000</phone_number>
      <tag>tag1</tag>
      <tag>tag2</tag>
    </person>
  XML
end

#resolve_path(raw, declaring_file) ⇒ Object

Resolve an autoload's raw string argument to a require path relative to LIB. Both common interpolation shapes resolve relative to the declaring file's directory, which is what MRI does for them.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/compat/opal/generate_boot.rb', line 47

def resolve_path(raw, declaring_file)
  declaring_dir = Pathname.new(declaring_file).dirname

  if raw.start_with?("\#{__dir__}/")
    subdir = raw.sub("\#{__dir__}/", "").delete_suffix(".rb")
    (declaring_dir + subdir).relative_path_from(LIB).to_s.delete_suffix(".rb")
  elsif raw.start_with?("\#{File.dirname(__FILE__)}/")
    subdir = raw.sub("\#{File.dirname(__FILE__)}/", "").delete_suffix(".rb")
    (declaring_dir + subdir).relative_path_from(LIB).to_s.delete_suffix(".rb")
  elsif raw.start_with?("lutaml/")
    raw.delete_suffix(".rb")
  else
    raw.delete_suffix(".rb")
  end
end