leptris 1.6.1 → 1.6.2

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: b2ea74c449e12497abc87b87d5c6196524540a586e077913e63f94a3b103fa3f
4
- data.tar.gz: 7f80cecd901a98c265539de2be30930d0cd58276f5425defa99a4917d89e4573
3
+ metadata.gz: 6cb4c2a8d3cb9da6f2c79fd03dc85b0f55f1a590b15a18ffedabd63177332f8e
4
+ data.tar.gz: df6b3611943af4f69c30d2a1650c86276fd89b7261f4d8da9dd43d6421b17de3
5
5
  SHA512:
6
- metadata.gz: 4267ae7e0d05eb64ddb9121af9d1ba5e99edc122cdcc338228b5b6660ece73e1d26ebde4b5a28885d512d892152feec0673bb06f2ae29fec1403885445ebcd85
7
- data.tar.gz: 755e4b1d239aa5fbdac57c15ffbb7c6876013bf9057e0eee2a893c0d0f417331ae469eb8ecc9ac6148425784fe38f06e4a7869b199bf3745222413ea9c6968f6
6
+ metadata.gz: 82fde4f6f7d6645c1eafe9d130f532437fb28703ab27aa6753d9afc2ad53f2eabb6e852bf8338b8e8c1e551225fd2548045430f93b2063cd31adf7c2e6132e2e
7
+ data.tar.gz: 726699586511ef79fdc5c51e4a102e49329c480bd66d39089c2dd0201c0d96117127f6a5cbb9a90051a115e0c130877c957e6342b124fb1a18211104a8bad591
data/CHANGELOG.md CHANGED
@@ -5,6 +5,16 @@ All notable changes to Leptris will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.6.2] - 2026-08-24
9
+
10
+ Lockstep with libleptris 1.6.2 (fix releases, no public API changes).
11
+
12
+ ### Changed
13
+
14
+ - CI/build pin libleptris v1.6.2, carrying the serializer fix for
15
+ mixed-content indentation (upstream #534 — never indent inside
16
+ mixed-content elements).
17
+
8
18
  ## [1.6.1] - 2026-08-24
9
19
 
10
20
  ### Added
@@ -51,6 +61,16 @@ release: pull (StAX) API, bounded iterparse, compiled XPath
51
61
  expressions, per-parse options, truthful serialization encoding
52
62
  declarations. Binding-side adoption of the new APIs follows.
53
63
 
64
+ ## [1.6.2] - 2026-08-24
65
+
66
+ Lockstep with libleptris 1.6.2 (fix releases, no public API changes).
67
+
68
+ ### Changed
69
+
70
+ - CI/build pin libleptris v1.6.2, carrying the serializer fix for
71
+ mixed-content indentation (upstream #534 — never indent inside
72
+ mixed-content elements).
73
+
54
74
  ## [1.6.1] - 2026-08-24
55
75
 
56
76
  ### Added
data/README.adoc CHANGED
@@ -136,6 +136,25 @@ doc.root.traverse do |node|
136
136
  end
137
137
  ----
138
138
 
139
+ == Readonly mode
140
+
141
+ For the dominant parse-query-serialize workload, parse with
142
+ `readonly: true` (or call `Document#readonly!`, one-way):
143
+
144
+ [source,ruby]
145
+ ----
146
+ doc = Leptris::XML.parse(xml, readonly: true)
147
+ doc.root.children.first["id"] # reads are memoized
148
+ doc.root.name # plain ivar after first call
149
+ doc.root << doc.create_element("x") # raises ReadOnlyError
150
+ ----
151
+
152
+ Reads (`name`, `content`, `children`, `attributes`) memoize
153
+ aggressively — they cannot go stale because mutation is forbidden.
154
+ Every mutator raises `Leptris::XML::ReadOnlyError`. Detached factories
155
+ (`create_element` and friends) still work: building a *new* tree
156
+ against a readonly document is legal; mutating the frozen one is not.
157
+
139
158
  == Searching: XPath and CSS
140
159
 
141
160
  `Document` and `Element` (via `Leptris::XML::Searchable`) support:
@@ -376,11 +395,66 @@ Notable differences:
376
395
 
377
396
  == Performance
378
397
 
379
- On the benchmark suite in `benchmark/leptris_vs_nokogiri.rb` (Ruby 3.3,
380
- libleptris v0.13+, macOS arm64), Leptris matches or beats Nokogiri on
381
- parse, XPath, serialize, and full-tree traverse for the small and
382
- medium documents that dominate real-world XML workloads. Run the
383
- benchmark locally for numbers on your hardware:
398
+ Measured with metanorma/serialbench (Ruby 3.4.8, leptris 1.6.0,
399
+ libleptris 1.6.0, macOS arm64) Leptris vs the full field:
400
+
401
+ [cols="2,1,1,1,1",options="header"]
402
+ |===
403
+ |Operation |Leptris |Ox |Nokogiri |vs Ox
404
+
405
+ |parse medium (300 KB)
406
+ |0.97 ms
407
+ |3.00 ms
408
+ |8.57 ms
409
+ |3.1x faster
410
+
411
+ |parse large (4.4 MB)
412
+ |13.51 ms
413
+ |77.06 ms
414
+ |104.22 ms
415
+ |5.7x faster
416
+
417
+ |generate medium
418
+ |1.75 ms
419
+ |14.19 ms
420
+ |23.93 ms
421
+ |8.1x faster
422
+
423
+ |generate large
424
+ |74.57 ms
425
+ |80.91 ms
426
+ |117.16 ms
427
+ |1.1x faster
428
+
429
+ |streaming medium
430
+ |0.73 ms
431
+ |103.82 ms
432
+ |43.74 ms
433
+ |142x faster
434
+
435
+ |streaming large
436
+ |8.52 ms
437
+ |204.14 ms
438
+ |239.14 ms
439
+ |24x faster
440
+
441
+ |Ruby allocations (medium)
442
+ |0.01 MB
443
+ |18.43 MB
444
+ |39.05 MB
445
+ |~1800x less
446
+ |===
447
+
448
+ Leptris takes first place on every XML operation above small-document
449
+ size, including against Ox (the C-extension speed champion). On
450
+ small-document micro-operations (sub-5 µs), C extensions hold an
451
+ inherent edge per call; Leptris's readonly mode closes the
452
+ steady-state gap by memoizing reads behind an immutability guarantee.
453
+
454
+ For XPath-heavy workloads, `Leptris::XML::XPath.compile` evaluates a
455
+ parsed expression repeatedly without re-parsing.
456
+
457
+ Run the local benchmark for numbers on your hardware:
384
458
 
385
459
  [source,shell]
386
460
  ----
@@ -392,7 +466,7 @@ bundle exec ruby benchmark/leptris_vs_nokogiri.rb
392
466
  [source,shell]
393
467
  ----
394
468
  bundle install # install Ruby deps
395
- bundle exec rspec # full test suite (176 specs)
469
+ bundle exec rspec # full test suite (229 specs)
396
470
  bundle exec rspec spec/xml/xpath_spec.rb:42 # one example by line
397
471
  bundle exec rubocop # lint
398
472
  ----
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ RSpec::Core::RakeTask.new(:spec)
8
8
  # Pin for `rake compile` and the platform-gem builds. Keep in lockstep
9
9
  # with .github/workflows/build.yml (which calls `rake compile`) and the
10
10
  # CHANGELOG when libleptris releases.
11
- LIBLEPTRIS_VERSION = "1.6.0"
11
+ LIBLEPTRIS_VERSION = "1.6.2"
12
12
 
13
13
  CMAKE_FLAGS = %w[
14
14
  -DCMAKE_BUILD_TYPE=Release
data/benchmark/README.md CHANGED
@@ -1,168 +1,12 @@
1
- # leptris-ruby vs Nokogiri — Ruby-level benchmarks
1
+ # leptris vs the field
2
2
 
3
- Compares `Leptris::XML` (FFI libleptris v0.12.0) against `Nokogiri::XML`
4
- (C extension → libxml2) on the operations that matter for typical use.
3
+ The authoritative cross-library numbers live in the README's
4
+ Performance section (measured with metanorma/serialbench).
5
5
 
6
- Run with:
6
+ This local benchmark compares against Nokogiri only:
7
7
 
8
- ```
9
- bundle exec ruby -Ilib benchmark/leptris_vs_nokogiri.rb
10
- ```
8
+ LEPTRIS_LIB_PATH=/path/to/libleptris.dylib bundle exec ruby benchmark/leptris_vs_nokogiri.rb
11
9
 
12
- ## Latest run (M1, libleptris v0.12.0, Nokogiri 1.19.4)
13
-
14
- All libleptris upstream issues closed (#166–#262, 21 issues total).
15
- v0.12.0 ships the [#262](https://github.com/leptris/leptris/issues/262) proposals:
16
- batch XPath result accessor (`leptris_xpath_result_get_nodes`) and per-node
17
- `binding_wrapper` field. The Ruby binding uses the batch accessor in
18
- `NodeSet#each`; the `binding_wrapper` is left for the libleptris team's
19
- other bindings (Python ctypes, etc.) — the Ruby binding's per-Document
20
- `ObjectSpace::WeakMap` cache is faster (no FFI call per cache lookup).
21
-
22
- Median of 3 runs (run-to-run variance is significant on cold starts and
23
- shared-runner workloads; the trend is stable):
24
-
25
- | Operation | Leptris | Nokogiri | Leptris / Nokogiri | Winner |
26
- |---|---:|---:|---:|---|
27
- | Parse small (431 B) | ~6 µs | ~14 µs | **~2×** | Leptris (variable) |
28
- | Parse medium (12 KB) | ~32 µs | ~200 µs | **~6×** | Leptris |
29
- | XPath `count(//book)` | ~1.5 µs | ~9 µs | **~6×** | Leptris |
30
- | XPath `//book` (100-node nodeset) | ~4 µs | ~13 µs | **~5×** | Leptris |
31
- | XPath `//book[@id='50']` (1 match) | ~6 µs | ~80 µs | **~10×** | Leptris |
32
- | XPath `//book[price > 50]` | ~80 µs | ~100 µs | **~1.3×** | Leptris |
33
- | XPath `//author \| //title` (union) | ~14 µs | ~25 µs | **~3×** | Leptris |
34
- | Tree traversal | ~900 µs | ~500 µs | 0.55× | Nokogiri (1.8× faster) |
35
- | Serialize | ~28 µs | ~85 µs | **~3×** | Leptris |
36
-
37
- **Leptris beats Nokogiri on 8 of 9 operations.** Only tree traversal still
38
- loses, by ~1.8×.
39
-
40
- ### Why tree traversal still loses
41
-
42
- `Node#traverse` visits every node and materializes each one via
43
- `Node.wrap`. The per-Document `ObjectSpace::WeakMap` cache helps on
44
- repeated traversals of the same doc but not on a single one. Each
45
- visited node pays:
46
- - 1 FFI call to `leptris_node_first_child` / `_next_sibling`
47
- - 1 FFI call to `leptris_node_get_type` (for wrap dispatch)
48
- - 1 Ruby object allocation (cache miss)
49
-
50
- Nokogiri's libxml2 C extension handles traversal in C and only crosses
51
- into Ruby when the user's block is called. No per-node FFI.
52
-
53
- The libleptris `binding_wrapper` field shipped in v0.12.0 doesn't help
54
- here in the Ruby binding — Ruby FFI still needs an FFI call to read
55
- `binding_wrapper`. The Ruby-side `WeakMap` cache avoids that FFI call
56
- on cache hits. So the binding's existing cache is already optimal for
57
- Ruby; the `binding_wrapper` field is more useful for bindings that
58
- don't have a native GC hook (Python ctypes, Go cgo, Rust bindgen).
59
-
60
- ## What changed from earlier runs
61
-
62
- ### v0.11.0 → v0.11.2 (binding-side)
63
-
64
- - **Lazy NodeSet** — `NodeSet.from_result` keeps the
65
- `LeptrisXPathResult*` alive (via `FFI::AutoPointer`) and materializes
66
- `self[i]` on demand. Eager materialization was the #1 cost.
67
- - **Per-Document wrapper cache** — `ObjectSpace::WeakMap` keyed on c_ptr
68
- address. Eliminates re-allocation on repeated access to the same node.
69
-
70
- ### v0.11.4 (libleptris-side)
71
-
72
- - **`leptris_xpath_result_get_nodes`** — batch accessor. The Ruby binding
73
- now uses this in `NodeSet#each` to fetch all node pointers in one FFI
74
- call instead of N calls.
75
-
76
- ### v0.12.0 (libleptris-side)
77
-
78
- - **`binding_wrapper` field on `LeptrisNode`** — present in the C struct
79
- but not used by the Ruby binding (see "Why tree traversal still loses"
80
- above). Useful for non-Ruby bindings.
81
- - **`#261` fix** — `benchmark-ips` on 38 KB docs no longer segfaults.
82
- All upstream issues closed.
83
-
84
- ### Before/after the binding + libleptris v0.12.0 optimizations
85
-
86
- | Operation | v0.11.0 (eager) | v0.12.0 (lazy + batch) | Speedup |
87
- |---|---:|---:|---:|
88
- | XPath `//book` (100 nodes) | 87.77 µs (0.15×) | ~4 µs (5×) | **22×** |
89
- | XPath union (200 nodes) | 188.40 µs (0.14×) | ~14 µs (3×) | **13×** |
90
- | XPath complex | 126.88 µs (0.67×) | ~80 µs (1.3×) | 1.6× |
91
- | Tree traversal | 1203 µs (0.50×) | ~900 µs (0.55×) | 1.3× |
92
-
93
- ## What this means for the v0.1.0 release
94
-
95
- - Leptris is the right choice for almost every Nokogiri workload on
96
- small-to-medium docs (≤20 KB): 2–10× faster than Nokogiri.
97
- - Tree-traversal-heavy workloads (single-pass DOM scraping where you
98
- touch every node once) are 1.8× slower than Nokogiri. Acceptable
99
- for v0.1.0; the binding could ship a "fast traverse" path later that
100
- skips wrapping for read-only blocks.
101
- - All known libleptris bugs are fixed. No upstream blockers.
102
-
103
- ## Analysis
104
-
105
- ### Where Leptris wins
106
-
107
- **Parse (1.69×–6.90×)** — libleptris's single-pass direct parser (the only
108
- parser since v0.11.0, after flat + legacy were deleted) is dramatically
109
- faster than libxml2's parser. The gap widens with document size.
110
-
111
- **XPath returning scalars (4.56×)** — `count()`, `boolean()`, `string()`,
112
- `number()` queries skip NodeSet materialization entirely. libleptris's XPath
113
- bytecode VM evaluates these in a single C call, no Ruby objects allocated
114
- per match.
115
-
116
- **XPath predicate match (13.01×)** — when the predicate narrows to a small
117
- result set (single match in this test), Leptris is much faster than
118
- Nokogiri/libxml2.
119
-
120
- **Serialize (2.84×)** — single C call into `leptris_document_serialize`,
121
- no Ruby traversal.
122
-
123
- ### Where Nokogiri wins
124
-
125
- **Nodeset-returning XPath (0.13×–0.16×)** — when a query returns a 100-node
126
- NodeSet, Leptris materializes every node eagerly (100× `Node.wrap` calls,
127
- each dispatching on `leptris_node_get_type`). Nokogiri caches wrappers
128
- lazily.
129
-
130
- **Tree traversal (0.49×)** — same root cause. `Node#traverse` creates a
131
- new wrapper per visited node via `Node.wrap`; Nokogiri reuses cached
132
- wrappers.
133
-
134
- ### Optimization opportunities (Ruby-side, no libleptris work needed)
135
-
136
- 1. **Lazy NodeSet materialization.** Currently `NodeSet.from_result`
137
- iterates the C result and calls `Node.wrap` for each entry on
138
- construction. Switch to lazy: keep the `LeptrisXPathResult*` alive,
139
- materialize `self[i]` on demand. Frees the eager 100× wrap.
140
- 2. **Node wrapper cache.** Weak-ref map keyed on the c_ptr address.
141
- `Node.wrap(ptr)` checks the cache first; only creates a new wrapper
142
- if none exists. Matches Nokogiri's behavior.
143
- 3. **Specialized traverse path.** For pure-traversal use cases (no
144
- per-node mutation), skip the wrapper and call FFI directly. Lower
145
- overhead but less idiomatic.
146
-
147
- ### Blockers
148
-
149
- **Parse-loop segfault on >20 KB docs with explicit `Document#free`
150
- (libleptris #256).** The v0.11.1 fix addressed one stale-thread-local
151
- path but not the parse+free cycle path. Long-running services and batch
152
- processors parsing medium/large XML cannot rely on the standard Ruby
153
- "let GC handle document lifetime" pattern OR the explicit `Document#free`
154
- pattern. Tracked upstream; workaround: cap doc size or avoid tight loops.
155
-
156
- **DOCTYPE PUBLIC/SYSTEM not exposed (libleptris #253).** Unrelated to
157
- benchmarks but blocks 4 Ruby specs. Low impact on perf-sensitive workloads.
158
-
159
- ## What this means for the v0.1.0 release
160
-
161
- - For **parse-heavy / XPath-aggregate / serialize** workloads on small-to-
162
- medium docs (≤20 KB): Leptris is clearly the right choice. 1.7-7× faster
163
- than Nokogiri.
164
- - For **heavy nodeset manipulation** (scraping, large DOM traversal):
165
- Nokogiri is faster today. The Ruby-side optimizations above would close
166
- most of the gap.
167
- - For **long-running services on medium/large docs**: blocked by #256
168
- until libleptris ships a complete fix.
10
+ For the full-field race (Ox, Nokogiri, Oga, REXML, Leptris), use
11
+ https://github.com/metanorma/serialbench — leptris's adapter ships
12
+ there under `lib/serialbench/serializers/xml/leptris_serializer.rb`.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Leptris
4
- VERSION = "1.6.1"
4
+ VERSION = "1.6.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leptris
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 1.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.