moxml 0.6.5 → 0.6.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e72bde533d70d24badbc7842d4b159d3117ce8012927058de45ed59eb5f0ea04
4
- data.tar.gz: bed3791ded78c2dc173b94e73d321c751fc542ad98a9799b05f68e677c1ac5eb
3
+ metadata.gz: c48f1775cb2f4eb3de69655fec93e1bb5d7ad5052b4ed4b82470a687ff2ccf96
4
+ data.tar.gz: a7ed111098b147489ca3c4b78c7ca3b2df121d669dc91074a478d1d87e2b5e64
5
5
  SHA512:
6
- metadata.gz: 216db2a989bf0d2543b68f458f38f18dd83200aaa16a903b7a5ee21c884c68f933d4ce41d4878944e37ab32b5e77488a1dffb232ce1898139cf0d65af4d60a9c
7
- data.tar.gz: bf51b0cd141d2225c494587000bdfe5f491d78d0f02edc5e0049a61948d4cfd1485b3fa233e26c2db475acb785ccab28084ab27cbb6945d59096cf66780cfcd1
6
+ metadata.gz: 30761cf2d3ebd5d745308cf86db52c19785ab34fb8356c11f6c06bc4b07ba00c765294de0cea52251fc535c05003f2bf14c0b664b0fbd35e9749ce9e362563f6
7
+ data.tar.gz: cd36f13d7b1296d4025ac852755e818661c4c47f17abb0b6d77cd1995ce28757939a9fe7ad5b47de741e8493a42f6e0f764843e6f9314336e3967a620750fb19
@@ -5,6 +5,26 @@ nav_order: 11
5
5
 
6
6
  == Performance considerations
7
7
 
8
+ === State of the art, honestly stated
9
+
10
+ Moxml wins every parity row on the published scoreboard — parse
11
+ 3.05x, attr pairs listing 7.35x, xpath count 3.04x, serialize 1.62x
12
+ of raw nokogiri — and loses exactly the structural rows, all at one
13
+ known place: the per-node wrapper mint and the per-read Ruby frame
14
+ (the facade's reads sit at ~331ns; the binding's own native read is
15
+ 71ns — the difference is one `bind_call` frame, the same cost every
16
+ Ruby-level wrapper pays). The asks that remove the last frame are
17
+ filed upstream with the floor tables (leptris-ruby#622: hot C reads
18
+ parameterized by subclass or a hydrated columnar walk,
19
+ klass-injected result mint, C set-attribute); adoption is
20
+ face-probed and lands behind gates the day upstream ships, the same
21
+ pattern as the six bulk-crossing surfaces already adopted.
22
+
23
+ Speed is the declared non-semantic channel: none of it is bought
24
+ with answers. The link:conformance.html[conformance dataset] runs
25
+ the model's committed rows on every tier, so a faster moxml is also
26
+ the same moxml.
27
+
8
28
  === Scoreboard (generated)
9
29
 
10
30
  `SCORE_PUBLISH=1 bundle exec ruby benchmark/scoreboard.rb` rewrites
@@ -31,7 +51,7 @@ Measurement: Ruby 3.3.13, leptris 1.9.383.0, nokogiri 1.19.4, 2026-10-26T23:05:1
31
51
  | `plan records (typed)` | 1.09x | data | informational
32
52
  |===
33
53
 
34
- *Parity rows* must stay at or above the 0.95 measurement floor. *Structural rows* are measured and trend-locked (10% regression tolerance) while their gaps remain open: per-node wrapper minting costs (#312 endgame) and engine construction. *Data API* rows are informational.
54
+ *Parity rows* must stay at or above the 0.95 measurement floor. *Structural rows* are measured and trend-locked (10% regression tolerance) while their gaps remain open: the per-node wrapper mint and per-read Ruby frame (the wrapper floor; removal asks filed upstream as leptris-ruby#622) and engine construction. *Data API* rows are informational.
35
55
  // SCOREBOARD:END
36
56
 
37
57
  === Memory management
@@ -59,6 +59,12 @@ checked in CI:
59
59
  | The published scoreboard: parity rows are commitments; structural
60
60
  gaps are measured and trend-locked, never hidden.
61
61
 
62
+ | link:conformance.html[Conformance dataset]
63
+ | The model's committed answers as data — 177 cases across 7
64
+ families, run row-for-row by the Ruby, Rust, and TypeScript tiers.
65
+ A mismatch on any row is a model finding, not a dialect
66
+ difference.
67
+
62
68
  |===
63
69
 
64
70
  Behind the pages, the consistency suite runs an engine-free
@@ -66,9 +72,10 @@ Behind the pages, the consistency suite runs an engine-free
66
72
  against every adapter; a seeded **generator** checks metamorphic
67
73
  properties over generated documents; and a whole-class **taxonomy
68
74
  differential** compares every adapter on every input class the model
69
- touches. The reference is itself transpiled to JavaScript and runs on
70
- the Opal lane.
71
-
75
+ touches. The same expectations export as the conformance dataset and
76
+ run in Rust (moxml-rs) and TypeScript (moxml-ts over the wasm
77
+ bundles) — one model implementation per language, all answering the
78
+ same rows.
72
79
  == What Moxml is not
73
80
 
74
81
  Moxml is not a new XML parser and does not replace the engines — it
@@ -3073,10 +3073,21 @@ module Moxml
3073
3073
  # converts per call (a Node.wrap + registry hit, ~6s/3M
3074
3074
  # allocations per million-element walk), and only mutation
3075
3075
  # faces need the binding element.
3076
+ # moxml#540: the bulk export serves RAW values (its engine
3077
+ # loop skips the lazy entity-run decode the single getters
3078
+ # apply). '&' cannot occur in a decoded value except through
3079
+ # an undecoded reference, so any '&' in the bulk output
3080
+ # re-serves the whole packet through attribute_packet, whose
3081
+ # values ride the decoding getter. Idempotent after the
3082
+ # engine gains the decode: the lazy decode replaced the
3083
+ # attribute's view, so the re-read answers the same bytes.
3076
3084
  if ELEMENT_ATTR_PACKET
3077
3085
  doc, addr = attr_packet_target(element)
3078
3086
  if doc
3079
3087
  flat = ::Leptris::XML::Native.attribute_pairs(doc, addr)
3088
+ if flat.any? { |v| v.is_a?(String) && v.include?("&") }
3089
+ flat = ::Leptris::XML::Native.attribute_packet(doc, addr)
3090
+ end
3080
3091
  return packet_attributes(flat, element)
3081
3092
  end
3082
3093
  end
@@ -3127,6 +3138,9 @@ module Moxml
3127
3138
  binding_element = to_binding(element)
3128
3139
  return super unless binding_element.respond_to?(:attribute_pairs)
3129
3140
 
3141
+ # attribute_packet (leptris_attribute_get_value) decodes
3142
+ # entity runs itself — moxml#540's guard applies only to the
3143
+ # attribute_pairs export, which serves raw values.
3130
3144
  pairs = if ELEMENT_ATTR_PACKET
3131
3145
  ::Leptris::XML::Native
3132
3146
  .attribute_packet(binding_element.document,
@@ -3193,6 +3207,21 @@ module Moxml
3193
3207
  SET_ATTRIBUTE_NATIVE =
3194
3208
  NATIVE_READ_LAYER && NN.method_defined?(:set_attribute)
3195
3209
 
3210
+ # TODO.perf/41 (leptris-ruby#622 ask 3): the module-level C
3211
+ # entry Native.set_binding_attribute(document, addr, name,
3212
+ # value) — free/readonly gates + binding-version bump + engine
3213
+ # set in one crossing. It serves the (document, address) pairs
3214
+ # the TypedData instance face cannot reach: AddressNode tokens
3215
+ # on the address-native lane and native nodes on exts without
3216
+ # the instance method. Semantically the bridge's twin: the
3217
+ # version bump IS the binding-memo invalidation (both
3218
+ # surfaces' memos drop on mutation), and callers invalidate
3219
+ # the wrapper caches exactly as before.
3220
+ SET_BINDING_ATTRIBUTE =
3221
+ NATIVE_READ_LAYER &&
3222
+ defined?(::Leptris::XML::Native) &&
3223
+ ::Leptris::XML::Native.respond_to?(:set_binding_attribute)
3224
+
3196
3225
  def set_attribute(element, name, value)
3197
3226
  # Native write face (leptris-ruby#204's nn_set_attribute):
3198
3227
  # gates + version bump + engine set in one C frame on the
@@ -3204,6 +3233,18 @@ module Moxml
3204
3233
  return element.set_attribute(name.to_s, value.to_s)
3205
3234
  end
3206
3235
 
3236
+ # TODO.perf/41: the module-level entry for the addressed
3237
+ # lane — one crossing instead of to_binding's Pointer wrap
3238
+ # + registry mint + memo'd hash write.
3239
+ if SET_BINDING_ATTRIBUTE
3240
+ doc, addr = attr_packet_target(element)
3241
+ if doc
3242
+ return ::Leptris::XML::Native.set_binding_attribute(
3243
+ doc, addr, name.to_s, value.to_s
3244
+ )
3245
+ end
3246
+ end
3247
+
3207
3248
  element = to_binding(element) if NATIVE_READ_LAYER
3208
3249
  element[name.to_s] = value.to_s
3209
3250
  end
@@ -4132,10 +4173,11 @@ module Moxml
4132
4173
  # AST walk is per-expression, so the verdict caches too.
4133
4174
  PARENT_AXIS_CACHE = XPath::Cache.new(100)
4134
4175
 
4135
- def xpath(node, expression, namespaces = {})
4176
+ def xpath(node, expression, namespaces = {}, context: nil)
4136
4177
  namespaces = normalize_xpath_namespaces(namespaces)
4137
4178
  node = to_binding(node) if NATIVE_READ_LAYER
4138
- native = native_xpath(node, expression, namespaces)
4179
+ native = native_xpath(node, expression, namespaces,
4180
+ context: context)
4139
4181
  return native unless native.nil?
4140
4182
 
4141
4183
  engine_xpath(node, expression, namespaces)
@@ -4164,9 +4206,10 @@ module Moxml
4164
4206
  hit.is_a?(::Moxml::Node) ? hit : node
4165
4207
  end
4166
4208
 
4167
- def at_xpath(node, expression, namespaces = {})
4209
+ def at_xpath(node, expression, namespaces = {}, context: nil)
4168
4210
  namespaces = normalize_xpath_namespaces(namespaces)
4169
- native = native_xpath(node, expression, namespaces, first_only: true)
4211
+ native = native_xpath(node, expression, namespaces,
4212
+ first_only: true, context: context)
4170
4213
  return native unless native.nil?
4171
4214
 
4172
4215
  result = engine_xpath(node, expression, namespaces)
@@ -4185,7 +4228,8 @@ module Moxml
4185
4228
 
4186
4229
  # @return [Array, Object, nil] native results, or nil when the
4187
4230
  # query must run on the Ruby engine
4188
- def native_xpath(node, expression, namespaces, first_only: false)
4231
+ def native_xpath(node, expression, namespaces, first_only: false,
4232
+ context: nil)
4189
4233
  # Canonical natives (the #219 unification) are bare TypedData
4190
4234
  # wrappers — no Searchable methods, no document handle for
4191
4235
  # the gates below. The memoized bridge recovers the binding
@@ -4307,7 +4351,8 @@ module Moxml
4307
4351
  # The one-crossing mint is deferred: a caller that only
4308
4352
  # asks #size never pays for the rows (#527). The holder
4309
4353
  # runs Document#xpath_result_rows_bulk on first read.
4310
- return Moxml::LazyBulkRows.new(document, result_ptr)
4354
+ return Moxml::LazyBulkRows.new(document, result_ptr,
4355
+ context, self)
4311
4356
  end
4312
4357
 
4313
4358
  # The binding's #to_a mints one Ruby wrapper per result
@@ -1086,7 +1086,10 @@ module Moxml
1086
1086
  end
1087
1087
  end
1088
1088
 
1089
- def xpath(node, expression, namespaces = nil)
1089
+ # rubocop:disable Lint/UnusedMethodArgument -- the protocol passes the
1090
+ # priming triple; engines without a bulk mint ignore it
1091
+ def xpath(node, expression, namespaces = nil, context: nil)
1092
+ # rubocop:enable Lint/UnusedMethodArgument
1090
1093
  native_node = unpatch_node(node)
1091
1094
  return [] unless native_node
1092
1095
 
@@ -647,7 +647,10 @@ module Moxml
647
647
  native.system_id
648
648
  end
649
649
 
650
- def xpath(node, expression, namespaces = nil)
650
+ # rubocop:disable Lint/UnusedMethodArgument -- the protocol passes the
651
+ # priming triple; engines without a bulk mint ignore it
652
+ def xpath(node, expression, namespaces = nil, context: nil)
653
+ # rubocop:enable Lint/UnusedMethodArgument
651
654
  if empty_default_namespace_binding?(namespaces)
652
655
  return Moxml::XPath.evaluate_natives(node, expression,
653
656
  namespaces,
@@ -587,7 +587,10 @@ module Moxml
587
587
  end
588
588
  end
589
589
 
590
- def xpath(node, expression, namespaces = nil)
590
+ # rubocop:disable Lint/UnusedMethodArgument -- the protocol passes the
591
+ # priming triple; engines without a bulk mint ignore it
592
+ def xpath(node, expression, namespaces = nil, context: nil)
593
+ # rubocop:enable Lint/UnusedMethodArgument
591
594
  # oga's engine has no xmlns: default-namespace idiom
592
595
  # (D-01); the reference engine implements it (model,
593
596
  # Names and namespaces).
@@ -715,7 +715,10 @@ module Moxml
715
715
  # with HeadedOx and Leptris). Ox's locate() only covers a
716
716
  # small XPath subset; the engine provides all axes,
717
717
  # predicates, functions and variables.
718
- def xpath(node, expression, namespaces = {})
718
+ # rubocop:disable Lint/UnusedMethodArgument -- the protocol passes the
719
+ # priming triple; engines without a bulk mint ignore it
720
+ def xpath(node, expression, namespaces = {}, context: nil)
721
+ # rubocop:enable Lint/UnusedMethodArgument
719
722
  wrapped = if node.is_a?(Moxml::Node)
720
723
  node
721
724
  else
@@ -640,7 +640,10 @@ module Moxml
640
640
  ns
641
641
  end
642
642
 
643
- def xpath(node, expression, namespaces = {})
643
+ # rubocop:disable Lint/UnusedMethodArgument -- the protocol passes the
644
+ # priming triple; engines without a bulk mint ignore it
645
+ def xpath(node, expression, namespaces = {}, context: nil)
646
+ # rubocop:enable Lint/UnusedMethodArgument
644
647
  # REXML's engine answers no text nodes for text() node
645
648
  # tests (D-07, both axes); the reference engine does
646
649
  # (model, XPath evaluation).
@@ -296,7 +296,8 @@ module Moxml
296
296
  def xpath(expression, namespaces = nil)
297
297
  expression = lax_document_path(expression) if relative_name_test?(expression)
298
298
 
299
- result = adapter.xpath(@native, expression, namespaces)
299
+ result = adapter.xpath(@native, expression, namespaces,
300
+ context: context)
300
301
 
301
302
  # Handle different result types:
302
303
  # - Scalar values (from functions): return directly
@@ -16,9 +16,17 @@ module Moxml
16
16
  class LazyBulkRows
17
17
  include LazyNodeSet
18
18
 
19
- def initialize(document, result_ptr)
19
+ # (context, adapter): the consumer contract triple for the primed
20
+ # mint (TODO.perf/40, leptris-ruby#622 ask 2) — the bulk face
21
+ # writes @mx_context/@mx_adapter in C and extends all-native
22
+ # results with BulkIdentityRows, so NodeSet's per-row wrap prime
23
+ # disappears from the iterate-every-result lane. nil (older
24
+ # bindings) keeps the unprimed mint.
25
+ def initialize(document, result_ptr, context = nil, adapter = nil)
20
26
  @document = document
21
27
  @ptr = result_ptr
28
+ @context = context
29
+ @adapter = adapter
22
30
  @rows = nil
23
31
  ObjectSpace.define_finalizer(
24
32
  self, self.class.finalizer(result_ptr.address)
@@ -62,7 +70,7 @@ module Moxml
62
70
  return @rows if @rows
63
71
 
64
72
  ObjectSpace.undefine_finalizer(self)
65
- @rows = @document.xpath_result_rows_bulk(@ptr)
73
+ @rows = @document.xpath_result_rows_bulk(@ptr, @context, @adapter)
66
74
  @ptr = nil
67
75
  @rows
68
76
  end
data/lib/moxml/node.rb CHANGED
@@ -415,7 +415,8 @@ module Moxml
415
415
  end
416
416
 
417
417
  def xpath(expression, namespaces = {})
418
- result = adapter.xpath(@native, expression, namespaces)
418
+ result = adapter.xpath(@native, expression, namespaces,
419
+ context: context)
419
420
  # Adapter contract: Array<native> | LazyNodeSet | scalar.
420
421
  # Scalars (count(), string-length(), booleans) pass through
421
422
  # unwrapped; the set forms wrap lazily.
@@ -476,7 +477,8 @@ module Moxml
476
477
  def css(expression)
477
478
  NodeSet.new(
478
479
  adapter.xpath(@native, Css.to_xpath(expression,
479
- absolute: document?)),
480
+ absolute: document?),
481
+ context: context),
480
482
  context,
481
483
  )
482
484
  end
data/lib/moxml/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Moxml
4
- VERSION = "0.6.5"
4
+ VERSION = "0.6.7"
5
5
  end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ # moxml#540: attribute values decode character references exactly as
6
+ # element text does (XML 1.0 §4.6). The leptris adapter's bulk packet
7
+ # face served the engine's raw attribute slice — entity runs stayed
8
+ # literal on #attributes while #text and the named getters decoded.
9
+ # The re-serve through the decoding packet face closes it; this spec
10
+ # pins the committed answer on every adapter so no adapter can serve
11
+ # a raw reference again.
12
+ RSpec.describe "attribute values decode character references" do
13
+ let(:xml) do
14
+ '<x a="&#x2190;" b="p&amp;q" c="&#8592;" d="plain" e="&#9;"/>'
15
+ end
16
+
17
+ let(:expected) do
18
+ {
19
+ "a" => "←",
20
+ "b" => "p&q",
21
+ "c" => "←",
22
+ "d" => "plain",
23
+ "e" => "\t",
24
+ }
25
+ end
26
+
27
+ it "decodes hex, decimal, and named references identically to text" do
28
+ Moxml::Adapter::AVAILABLE_ADAPTERS.each do |name|
29
+ begin
30
+ ctx = Moxml.new(name)
31
+ root = ctx.parse(xml).root
32
+ rescue Moxml::Error, NotImplementedError, LoadError
33
+ next
34
+ end
35
+
36
+ got = root.attributes.to_h { |a| [a.name, a.value] }
37
+ expect(got).to eq(expected),
38
+ "#{name}: #{got.inspect}"
39
+ end
40
+ end
41
+
42
+ it "matches the element-text decode on the same document" do
43
+ ctx = Moxml.new(:leptris)
44
+ doc = ctx.parse('<x a="&#x2190;">&#x2190;</x>')
45
+ expect(doc.root.attributes.first.value).to eq(doc.root.text)
46
+ end
47
+
48
+ it "keeps the attribute_pairs bulk face consistent with #attributes" do
49
+ ctx = Moxml.new(:leptris)
50
+ root = ctx.parse(xml).root
51
+ pairs = Moxml::Adapter.load(:leptris).attribute_pairs(root.native)
52
+ got = pairs.to_h { |qualified, value| [qualified, value] }
53
+ expect(got.values_at("a", "b", "c", "d", "e"))
54
+ .to eq(expected.values)
55
+ end
56
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moxml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.5
4
+ version: 0.6.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-11-11 00:00:00.000000000 Z
11
+ date: 2026-11-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  Moxml is a unified XML manipulation library that provides a common API
@@ -326,6 +326,7 @@ files:
326
326
  - sig/moxml.rbs
327
327
  - spec/consistency/README.md
328
328
  - spec/consistency/adapter_parity_spec.rb
329
+ - spec/consistency/attribute_charref_decode_spec.rb
329
330
  - spec/consistency/citation_hygiene_spec.rb
330
331
  - spec/consistency/conformance_families_spec.rb
331
332
  - spec/consistency/differential_taxonomy_spec.rb