leptris 1.9.415.0-aarch64-linux → 1.9.417.0-aarch64-linux

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: 643a3ccc15071884acf65ab2cd2a0f25e510d3515485a854046875e8be909556
4
- data.tar.gz: c18482d2627eda5ba40e9c8a5c11923b5d0ce2b3c1db7dd3f5de88c5592eeddd
3
+ metadata.gz: 04c9ccea0b07bb0494046ce519be95ba181a8fd4486c3a9570f49eb2a4c1a0d0
4
+ data.tar.gz: 6cb755a997496cbf4b0e727bd7e4594a21251d6f2be86196fea15fcbf9568f95
5
5
  SHA512:
6
- metadata.gz: c0368767bce157e9d83da315732e5c0daade5f2b19a4b7707e6e6f47021934e764d46b9efb29b15f12059d89fbe761f211ea5d71d231eeb3e7882eddf51b49ba
7
- data.tar.gz: 5559d9cb36c974107c31c505674c194c82afae622455349c92ac93079297f54c9db82dc4ee57bf69b0b0f91fce0d40d0d21079e4487b7f450516bba06e26461f
6
+ metadata.gz: b229e68e7ea6e1ebd871505d5a0b8569c97b05e6bdfd55292c767d9f5475e441aa17d76f52dd61da4f06c0912317355abc58097f02fbcc66a8144fa4bb4f036b
7
+ data.tar.gz: 668c50ac13ef120d87043f438bea9ed0795c4e94738c20d6806ce3085c4d163f5af01d8f8dbc5c76ece1fd63ee0112094a0d331e0fe60fd6f8e4034753cbcb34
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.9.415"
11
+ LIBLEPTRIS_VERSION = "1.9.417"
12
12
  # Vendored alongside libleptris for fn:normalize-unicode (TODO
13
13
  # .restructure/20): built per platform with a RELOCATABLE @rpath
14
14
  # install name, loaded by ffi.rb before libleptris so the
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Leptris
4
- VERSION = "1.9.415.0"
4
+ VERSION = "1.9.417.0"
5
5
  end
data/lib/libleptris.so CHANGED
Binary file
data/vendor-src/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Sources vendored in this gem (recompile rights; the ruby
2
2
  variant builds them at install via extconf.rb):
3
3
 
4
- - libleptris v1.9.415
4
+ - libleptris v1.9.417
5
5
  - utf8proc v2.11.0
6
6
 
7
7
  Rebuild by hand:
@@ -1,5 +1,39 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.9.417] - 2026-11-11
4
+ ## Performance
5
+
6
+ - **parse: inline the no-attribute fast-out in the element-open path** (#1842 Track D). The text-shape profile showed `dp_parse_attrs` at ~5% of a document with zero attributes — the per-element call + reset prologue + dup-table memset paid even for `<e></e>`-class tags. `>` or `/` directly after the element name collapses to a few inline stores; whitespace falls through to the full parser unchanged. CI shape rows: ubuntu-x86 attr 13MB reached **parity (0.99x)**, text rows +52–54%, attr 1.5MB **ahead (0.72x)**.
7
+
8
+ - **parse: content-census-driven arena copy budget** (#2003). The count3 sizing pre-scan now also census-counts `&` and literal tab/LF/CR (the only content-copy sources: entity expansion, §3.3.3 normalization) in the same SIMD pass; documents carrying neither drop the len-sized copy reservation — arena ~3x len → ~2x len for the machine-generated single-line class.
9
+
10
+ - **parse: skip the pristine buffer carve for newline-free documents** (#2005, A3d). The pristine copy existed for the lazy line table; a newline-free document loses no newlines to `dp_nul`, so the carve and its full-buffer memcpy drop and `xml_buffer` repoints at the doc-owned scratch. macos attr-13MB +189%.
11
+
12
+ - **simd: count3_high gains an AVX2 kernel** (#2006). x86 machines ran the sizing pre-scan SCALAR; five counters in one 32-byte-chunk pass. The ubuntu-x86 text rows moved 3.4–3.5x behind → 1.38–1.46x.
13
+
14
+ ## Benchmarks
15
+
16
+ - The attrparse row is now win/parity on all three CI legs (macos 1.10x, ubuntu-x86 1.04x, ubuntu-arm 0.84). The macos 13MB shape rows were re-classified as runner noise (4.8x swings across runs of near-identical code) — verdicts there require repeated-run medians. Full arc and the remaining lever (the fused scanner loop on the arm legs) ledgered in `TODO.max-perf/15` Track D addenda 1–6b.
17
+
18
+ ## Documentation
19
+
20
+ - README's shape table refreshes with the noise classification; negative results ledgered (the interleaved-lane default flip measured 1.72x slower on element-dense shapes — the opt-in gate stands).
21
+
22
+ ## [1.9.416] - 2026-11-11
23
+ ## Performance
24
+
25
+ - **parse: the attribute dup-table stops rehashing small documents** (#1842 Track D). Growth was ×8, so an element with ≥14 attributes blew the 14-slot threshold inside a 16-slot table and every such document paid a 512B pool alloc + memset + full rehash on its first element; later elements memset 512B each. ×2 growth keeps the common ≤16-attr element at 32 slots (load ≤50%, ~1 probe step) with no growth, and wide elements still grow geometrically.
26
+ - **parse: the dup-probe fast path is inlined** in `dp_add_attr_inline` — the per-attribute out-of-line call (alloc/grow slow-paths stay out-of-line) was ~10% of the no-inline attrparse profile. Canonical CI bench: ~30-45 ns/doc on the attr-dense shape.
27
+
28
+ ## Benchmarks
29
+
30
+ - **The attrparse row is CI-gated and platform-split.** `bench_append_attr_pugixml` now runs in the Benchmark workflow on quiet GH runners (Release + LTO, min of 5) with a new ubuntu-24.04-arm leg. First gated rows: macos-latest **1.11x win** (1830.8 vs 2036.6 ns/doc); ubuntu-24.04-arm 1.13x behind (gcc-13 + glibc, mild); ubuntu-latest x86-64 1.46x behind — the extra ~30% is isolated as **x86-64-specific codegen of the fused scanner under gcc-13** (same toolchain family on arm64 is healthy; gcc-16/arm64 builds leptris faster than clang locally). Run-to-run CI variance is ~5-10%; all verdicts sit outside that band.
31
+ - The same run's `bench_parse_ab` names the next parse gaps with CI-gated shape data: text-shape parse 1.6x behind pugixml on macos and 3.3x on ubuntu-x86; documents at ~13MB collapse to 5.1-5.8x behind on macos (the arena reservation sums ~3x the input length — scratch + pristine + text-room are each len-sized). Full ledger in `TODO.max-perf/15` Track D.
32
+
33
+ ## Documentation
34
+
35
+ - README's attribute-dense section now reads from CI artifacts with the platform-split table; negative results ledgered so they are not re-attempted (inline 16B SIMD value scan = 20% regression at ~11-byte values; count3 small-doc skip dead-ends into an allocator-bin cliff; the interleaved lane is not faster below the small-doc threshold).
36
+
3
37
  ## [1.9.415] - 2026-11-10
4
38
  ## Performance
5
39
 
@@ -3,7 +3,7 @@
3
3
  cmake_minimum_required(VERSION 3.20)
4
4
 
5
5
  project(leptris
6
- VERSION 1.9.415
6
+ VERSION 1.9.417
7
7
  DESCRIPTION "Fast XML parser and XPath evaluator in pure C"
8
8
  LANGUAGES C CXX
9
9
  )
@@ -1084,33 +1084,89 @@ removed by the lane-18 append/attr work)
1084
1084
 
1085
1085
  ==== Attribute-dense parse+read (vs pugixml) — 2026-11 refresh
1086
1086
 
1087
- Numbers from `bench_append_attr_pugixml` (the `attrparse` rows),
1088
- methodology corrected in v1.9.414: the workload is parse + walk +
1089
- read every attribute name and value on BOTH engines (the previous
1090
- revision measured parse-without-access, which compared leptris's
1091
- deferred-until-touch handle against pugixml's eager parse), taking
1092
- the MIN of 5 repetitions.
1087
+ Numbers from `bench_append_attr_pugixml`, CI-gated since this
1088
+ revision: the bench runs in the Benchmark workflow on quiet GH
1089
+ runners (Release + LTO, min of 5) on ubuntu-latest, ubuntu-24.04-arm,
1090
+ and macos-latest — the rows below are those artifacts, not local
1091
+ runs. The bench's attrparse row is parse + free per document (20k
1092
+ docs, 4 elements x 16 attributes); the local parse+walk+read
1093
+ harness numbers are noted separately.
1093
1094
 
1094
1095
  [cols="2,>1,>1,>1",options="header"]
1095
1096
  |===
1096
- |Benchmark |Leptris |pugixml |Verdict
1097
+ |Benchmark (parse + free, CI-gated) |Leptris |pugixml |Verdict
1097
1098
 
1098
- |Parse+read 64-attr doc (default flags)
1099
- |~1.6 µs
1100
- |~1.4 µs
1101
- |parity (1.15x; user-CPU equal at 4M docs)
1099
+ |macos-latest (clang, arm64)
1100
+ |1512.4 ns/doc
1101
+ |1492.4 ns/doc
1102
+ |parity (1.01x)
1102
1103
 
1103
- |Parse+read (Door A: skip dup + positions)
1104
- |~1.55 µs
1105
- |~1.4 µs
1106
- |parity
1104
+ |ubuntu-latest (x86-64, gcc-13)
1105
+ |1709.6 ns/doc
1106
+ |1891.3 ns/doc
1107
+ |**1.10x faster**
1107
1108
 
1108
- |Full-window CPU-clock head-to-head (4M docs)
1109
+ |ubuntu-24.04-arm (gcc-13, glibc)
1110
+ |2222.4 ns/doc
1111
+ |1850.2 ns/doc
1112
+ |1.20x slower
1113
+
1114
+ |Full-window CPU-clock head-to-head, 4M docs (local, LTO both sides)
1109
1115
  |5.45 s user
1110
1116
  |5.45 s user
1111
- |**equal — user-CPU parity**
1117
+ |equal — user-CPU parity
1118
+ |===
1119
+
1120
+ The shape-fair parse rows (`bench_parse_ab`, same CI run) after the
1121
+ content-census copy budget (#2003), the pristine-copy skip for
1122
+ newline-free documents (#2005), and the AVX2 sizing pre-scan
1123
+ (#2006):
1124
+
1125
+ [cols="2,>1,>1,>1",options="header"]
1126
+ |===
1127
+ |Row (MB/s, leptris vs pugixml) |Before the cuts |After |Delta
1128
+
1129
+ |ubuntu-x86 text 1.5/5/13 MB
1130
+ |3.4-3.5x behind
1131
+ |1.16-1.46x behind
1132
+ |+181-276%
1133
+
1134
+ |ubuntu-x86 attr 1.5 MB
1135
+ |1.37x behind
1136
+ |**ahead (0.72x)**
1137
+ |+176%
1138
+
1139
+ |ubuntu-x86 attr 5 MB
1140
+ |1.36x behind
1141
+ |near-parity (0.90x)
1142
+ |+118%
1143
+
1144
+ |ubuntu-x86 attr 13 MB
1145
+ |1.36x behind
1146
+ |parity (0.99x)
1147
+ |+103%
1148
+
1149
+ |macos text 1.5/5/13 MB
1150
+ |1.66-1.87x behind
1151
+ |1.57-2.01x (runner-noise band; see note)
1152
+ |single-run macos 13MB rows swing 4.8x between runs — medians required
1153
+
1154
+ |macos attr 13 MB
1155
+ |5.14x behind
1156
+ |unstable (104-504 MB/s across runs)
1157
+ |the row is runner noise; verdicts from repeated-run medians only
1112
1158
  |===
1113
1159
 
1160
+ The macos 13MB rows oscillate up to 4.8x between runs of
1161
+ near-identical code (139/174/504/104 MB/s across this arc) — the
1162
+ macos lane needs repeated-run medians before any single-run verdict
1163
+ there. The stable legs (ubuntu-x86, ubuntu-arm) carry the verdicts.
1164
+
1165
+ Run-to-run CI variance is ~5-10%; all verdicts sit outside that band
1166
+ except the macos parity row. Findings and the remaining honest tail
1167
+ (the fused scanner loop on the arm legs) live in `TODO.max-perf/15`
1168
+ Track D.
1169
+
1114
1170
  ==== Recent performance wins (v1.9.410-v1.9.414)
1115
1171
 
1116
1172
  Each release-verified via ABBA with fresh RelWithDebInfo+LTO builds:
@@ -131,3 +131,207 @@ whole tree to assign ranks (#485 table).
131
131
  - #1218: arena estimates only ever grow.
132
132
 
133
133
  Refs #1842, serialbench-c#8.
134
+
135
+ ## Track D — attr-dense parse+read row (post-#1842 closure, 2026-11-11)
136
+
137
+ The row's CI gate was missing: `bench_append_attr_pugixml` was NOT in
138
+ the benchmark.yml binary list, so the attrparse row had no
139
+ quiet-runner arbiter (the 2026-11-09 numbers were local). NOW WIRED
140
+ (this commit): the binary joins the CI benchmark legs (ubuntu + macos,
141
+ Release + LTO, quiet GH runners). The row's verdict comes from those
142
+ artifacts.
143
+
144
+ Fresh profile (2026-11-11, no-inline attribution, attrparse shape 4x16
145
+ attrs): dp_parse_attrs 37% | dp_add_attr_inline 20% | dup table 10% |
146
+ strlen faces 10% | count3-neon 4.3% | attributes_raw 3.7% | map
147
+ mutex+TLS 2.7% | dp_nul 2%.
148
+
149
+ Cut ledger:
150
+ - [x] dup-table growth x8 -> x2 (16-attr elements no longer pay a
151
+ 512B rehash per doc).
152
+ - [x] dup-probe fast path INLINED in dp_add_attr_inline (~30-45
153
+ ns/doc; the per-attr out-of-line call was the cost).
154
+ - [x] REVERTED: inline 16B SIMD value scan (NEON/SSE2) — a 20%
155
+ REGRESSION for the ~11-byte values the shape has: one chunk of
156
+ 5x cmpeq + vpadd-ladder movemask loses to the branch-fused
157
+ scalar table loop at short lengths. The 48-byte inline probe
158
+ threshold was already tuned; do not re-attempt below ~64B.
159
+ - [ ] count3 small-doc inline: DEAD END — without the scan the
160
+ arena sizing needs len-derived upper bounds that over-reserve
161
+ ~3x and push small-doc arenas into bigger allocator bins
162
+ (the madvise teardown cost the slack floor already fights).
163
+ - [ ] A3d pristine-copy skip for newline-free docs (count3 gains a
164
+ 4th counter): PARKED — the declaration's version/encoding
165
+ views BORROW doc->xml_buffer; switching them to the scratch
166
+ needs the borrowed-pointer topology audited first.
167
+ - The interleaved lane (LEPTRIS_IL_MIN=0) is NOT faster on this
168
+ shape (measured; the small-doc threshold stands).
169
+
170
+ Local measurement discipline note: under parallel agent load,
171
+ leptris degrades ~20% while pugixml stays flat (leptris's scratch +
172
+ pristine + arena working set is far more cache-sensitive). Loaded
173
+ ratios are meaningless; the CI artifacts gate this row from here on.
174
+
175
+ ## Track D addendum — the first CI-gated numbers (2026-11-11, PR #2001)
176
+
177
+ bench_append_attr_pugixml's first quiet-runner rows SPLIT BY PLATFORM:
178
+ - macos-latest: leptris 1728.6 vs pugixml 2182.9 — leptris 1.26x WIN.
179
+ - ubuntu-latest: leptris 2798.6 vs pugixml 1885.2 — leptris 1.48x LOSS.
180
+
181
+ The ubuntu anomaly is NOT attr-specific: benchmark_parse (tiny/small/
182
+ medium, cold-start) shows pugixml ahead on BOTH legs at 0.52-0.65x
183
+ (macos) but 0.31-0.40x (ubuntu) — the ubuntu factor roughly DOUBLES
184
+ leptris's deficit on every small-parse shape. pugixml is FASTER on
185
+ ubuntu than macos (1885 vs 2183), so runner speed does not explain it.
186
+
187
+ Compiler dimension isolated locally: gcc-16/arm64 builds leptris
188
+ FASTER than clang (1428 vs 1500, same machine, same clang-built
189
+ pugixml dylib) — the arm64/gcc dimension is healthy. The suspect set
190
+ is gcc-13 x86-64 codegen on the fused scanner or a glibc interaction;
191
+ ubuntu-24.04-arm joins the benchmark matrix to split the dimension
192
+ (same gcc-13 + glibc, different arch+codegen).
193
+
194
+ Slack-floor shrink for small docs: DO NOT re-attempt — #1846
195
+ falsified it (the retained pool amortizes the reservation; measured
196
+ 0.9743x = negative).
197
+
198
+ ## Track D addendum 2 — the three parse-vs-pugixml gaps (CI-gated, 2026-11-11)
199
+
200
+ bench_parse_ab in the same CI run (shape-fair MB/s) splits the parse
201
+ deficit into three NAMED gaps, none attr-specific:
202
+
203
+ 1. **Text-shape scanner gap**: text 1.5/5MB = leptris 1290-1322 MB/s
204
+ vs pugixml 2086-2199 (1.6x) on macos; 573-577 vs 1896 (3.3x!) on
205
+ ubuntu. This is Track A's scanner surgery with a platform shape:
206
+ the text-run fused loop is where the ubuntu-x86 codegen collapses.
207
+ 2. **The 13MB collapse (macos)**: attr 502->139 MB/s, text 1290->362
208
+ as the doc grows to 13MB (5.1-5.8x behind). The arena reservation
209
+ sums ~3x len (scratch_bytes + pristine_bytes + text_room are EACH
210
+ len-sized, plus elem/attr/slack terms) -> ~40MB reserved + 2
211
+ full memcpys per parse. Levers: drop the pristine copy when the
212
+ input has no newlines (A3d, parked on the borrowed-pointer audit),
213
+ and fold text_room into scratch (text nodes are substrings of the
214
+ scratch; text_room's 64B/node overhead is the only true extra).
215
+ 3. **The ubuntu x-factor**: leptris 2798 vs its own macos 1728 on the
216
+ SAME source+flags (62% self-slowdown) while pugixml runs FASTER on
217
+ ubuntu (1885 vs 2183). gcc-16/arm64 local = healthy. The
218
+ ubuntu-24.04-arm CI lane (this PR) splits gcc-13-x86 codegen from
219
+ glibc. Candidate micro-levers once the dimension is known:
220
+ -fno-plt / mmap-threshold pinning (mallopt) / loop restructuring
221
+ where gcc-13 jump-threading bails.
222
+
223
+ ## Track D addendum 3 — the ubuntu dimension RESOLVED (2026-11-11, all three CI legs)
224
+
225
+ attrparse rows from the final three-leg CI run (same commit):
226
+ - macos-latest (clang arm64): leptris 1830.8 vs pugixml 2036.6 — WIN 1.11x.
227
+ - ubuntu-24.04-arm (gcc-13 + glibc, arm64): 2091.7 vs 1850.3 — loss 1.13x.
228
+ - ubuntu-latest (gcc-13 + glibc, x86-64): 2793.4 vs 1914.7 — loss 1.46x.
229
+
230
+ Decomposition: gcc-13+glibc on arm64 costs ~0.02-0.2x (mild); the
231
+ EXTRA ~30% penalty is x86-64-SPECIFIC codegen of the fused scanner
232
+ under gcc-13. The lever: gcc-13-x86 scanner codegen (jump-threading /
233
+ register allocation in direct_parse_internal), CI-leg-verified with
234
+ the x86 lane as the gate. pugixml again ran FASTER on ubuntu hardware
235
+ than macos on both linux legs — the hardware/allocator dimension
236
+ favors it; leptris's own linux penalty is the 1.13x arm number.
237
+
238
+ Also note run-to-run variance: the macos attrparse pair measured
239
+ 1728/2183 then 1831/2037 across runs (~5-10%) — treat sub-10% CI
240
+ deltas as noise bands; the win/loss verdicts above sit outside them.
241
+
242
+
243
+ ## Track D addendum 4 — the arena cut LANDED (PR #2003, 2026-11-11)
244
+
245
+ Content-census copy budget (count3_high amp/valws outputs): macos
246
+ 13MB collapse CONFIRMED as the reservation — CI-gated bench_parse_ab
247
+ before/after: text 13MB 361.6 -> 794.2 MB/s (+120%), attr 13MB
248
+ 139.4 -> 174.4 (+25%); the 13MB gaps halved (5.8x -> 2.57x text,
249
+ 5.14x -> 3.84x attr). macos attr-5MB measured -32% in the same run —
250
+ single-datapoint between-run variance on that row (two runs only);
251
+ watch it on the next run before treating as real.
252
+
253
+ Remaining 13MB terms: scratch (len, required) + pristine (len, A3d
254
+ parked on the borrowed-decl audit). NEXT LEVER CANDIDATES, in order:
255
+ (a) A3d pristine skip — needs the decl-views audit (direct_parse.c
256
+ borrowed version/encoding point INTO xml_buffer);
257
+ (b) parse-path arena reuse (thread-local spare-span recycle, the
258
+ #1846 warm-span idea applied to fresh parse arenas — amortizes the
259
+ per-doc mmap/fault churn that dominates large-doc create/free
260
+ loops);
261
+ (c) ubuntu-x86 scanner codegen (gcc-13; the 1.35-3.7x rows there are
262
+ now the widest platform gap).
263
+
264
+ ## Track D addendum 5 — A3d (PR #2005) + AVX2 pre-scan (PR #2006) LANDED
265
+
266
+ A3d (pristine skip for the newline-free class), macos CI verdicts:
267
+ attr 13MB 174.4 -> 503.7 MB/s (+189%), text 13MB 794.2 -> 1366.9
268
+ (+72%); 13MB gaps 5.14x -> 2.18x attr, 5.80x -> 1.87x text across
269
+ the two cuts (#2003 census + #2005 pristine). The attr-5MB -32% from
270
+ addendum 4 was between-run variance (+78% this run). ubuntu ratios
271
+ held (that leg itself ran slower; pugixml moved with it).
272
+
273
+ count3_high's AVX2 kernel (#2006) TRANSFORMED the ubuntu-x86 lane —
274
+ the SCALAR sizing pre-scan was the dominant tax there, NOT scanner
275
+ codegen: attr 1.5MB 286.5 -> 582.7 MB/s (NOW AHEAD: 0.75x), attr
276
+ 5MB 1.36x -> 0.93x, attr 13MB 1.36x -> 1.03x (parity), text
277
+ 1.5/5/13MB 3.41x/3.37x/3.50x -> 1.45x/1.38x/1.69x. Runner variance
278
+ caveat noted (pugixml's rows moved too); the deltas are far outside
279
+ those bands.
280
+
281
+ Soundness note for A3d: parse_string frees the caller's buffer by
282
+ contract — the skip repoints xml_buffer at the doc-owned SCRATCH
283
+ (newline-free: no dp_nul clobber can lose a newline), never the
284
+ caller's const buffer. Teeth: NewlineTerminatedNameNeedsPristine
285
+ parses `a\n='1'` (whitespace before '=' is legal; an attr NAME can
286
+ be newline-terminated) — RED under unconditional skip, GREEN gated.
287
+ Two pin drafts discarded for wrong premises (element names are not
288
+ NUL'd; `<e a b='1'>` is malformed XML). Also learned: the eager
289
+ line-breaks table in direct_parse_internal is OOM-path-only; the
290
+ live resolver is node_public.c's lazy table off xml_buffer.
291
+
292
+ REMAINING (the honest tail): ubuntu-x86 text 1.38-1.69x, attr
293
+ 0.75-1.03x (parity-to-ahead!), arm text ~1.9-2.1x, macos text 13MB
294
+ 1.87x — the fused scanner loop is the one lever left, and the
295
+ platform picture is now win/parity-adjacent everywhere instead of
296
+ 2-5x behind.
297
+
298
+ ## Track D addendum 6 — the text-shape profile + the IL-default rejection (PR #2009)
299
+
300
+ Fresh no-inline text-shape attribution (300k elements, 19MB, classic
301
+ lane): direct_parse_internal own body 34% | text_scan_run_neon 17% |
302
+ dp_wire_child 9% | memmove (scratch copy) 8.2% | count3_neon 7.9% |
303
+ dp_text_create 7.4% | dp_parse_attrs 5% | pos journal 3.3% | edge
304
+ encode 3%.
305
+
306
+ LANDED: the no-attribute fast-out (dp_parse_attrs' 5% on a zero-attr
307
+ doc = per-element call + prologue + dup memset).
308
+
309
+ REJECTED BY MEASUREMENT: flipping LEPTRIS_INTERLEAVED's default on —
310
+ the IL lane measured 1.72x SLOWER user-CPU on the element-dense-
311
+ with-text 19MB fixture (the record pass + replay outweigh the fused
312
+ copy on this shape). The opt-in gate + 64KB threshold stand; the
313
+ lane's large-doc wins are shape-specific. (Second finding: the lane
314
+ is env-gated OFF in CI rows — every published bench_parse_ab number
315
+ is the classic lane.)
316
+
317
+ THE REMAINING ARC (unchanged): direct_parse_internal's own body —
318
+ the per-tag dispatch, name scan, close-tag match, and per-node
319
+ bookkeeping spread across wire/pos/edge-create. Instruction-level,
320
+ multi-session. The per-node bookkeeping share (wire 9% + text_create
321
+ 7.4% + pos 3.3% + edge 3% = ~23%) is the largest coherent block;
322
+ a layout-level pass (fewer, wider stores per node) is the shape of
323
+ the next slice if the campaign continues.
324
+
325
+ ## Track D addendum 6b — the fast-out's CI verdict + the macos-noise proof (PR #2009)
326
+
327
+ The no-attribute fast-out delivered on the stable legs: ubuntu-x86
328
+ attr 5/13MB +31-32% (13MB now PARITY at 0.99x), attr 1.5MB 0.72x
329
+ (win deepening), text 1.5/5/13MB +52/53/54% (1.27x/1.16x/1.46x);
330
+ ubuntu-arm text rows all up (937->978, 939->984, 872->906).
331
+
332
+ THE MACOS 13MB ROWS ARE RUNNER NOISE: attr-13MB measured
333
+ 139.4 -> 174.4 -> 503.7 -> 104.3 MB/s across runs of
334
+ near-identical code (the cuts only ADD work-free fast paths) —
335
+ a 4.8x swing on one leg. Single-run macos attr/text-13MB datapoints
336
+ MUST NOT drive verdicts; the macos lane needs repeated-run medians
337
+ before any row there is called a regression or a win.
@@ -49,6 +49,16 @@ extern "C" {
49
49
  /**
50
50
  * Parse XML string into document
51
51
  *
52
+ * Parsing is EAGER and SYNCHRONOUS: the full node tree is built
53
+ * before the call returns, so the first access costs the same as
54
+ * every later one (verified against the 2026-11-10 benchmark
55
+ * artifact where a no-touch loop was mistaken for deferred
56
+ * construction — the loop never re-entered the parser per
57
+ * iteration). Only two facets stay lazy by design INSIDE the
58
+ * built tree: predefined entity text (&amp; &lt; ...) materializes
59
+ * on first text read, and per-element namespace caches fill on
60
+ * first namespace query.
61
+ *
52
62
  * @param xml XML string (must be valid UTF-8)
53
63
  * @param length Length of XML string in bytes
54
64
  * @param status Output status code (can be NULL)
@@ -108,7 +108,7 @@ static void (*g_count3_fn)(const char*, size_t, char, char, char,
108
108
  size_t*, size_t*, size_t*) = NULL;
109
109
  static void (*g_count3_high_fn)(const char*, size_t, char, char, char,
110
110
  size_t*, size_t*, size_t*,
111
- int*) = NULL;
111
+ int*, size_t*, size_t*) = NULL;
112
112
  static void (*g_copy3_fn)(char*, const char*, size_t, char, char, char,
113
113
  size_t*, size_t*, size_t*) = NULL;
114
114
  static int (*g_utf8_fn)(const char*, size_t) = NULL;
@@ -157,10 +157,16 @@ static void dispatch_init(void);
157
157
  int leptris_utf8_valid_scalar(const char* s, size_t len);
158
158
  int leptris_utf8_valid_avx2(const char* s, size_t len);
159
159
  int leptris_utf8_valid_neon(const char* s, size_t len);
160
+ void leptris_text_count3_high_avx2(const char* s, size_t len,
161
+ char c0, char c1, char c2,
162
+ size_t* n0, size_t* n1, size_t* n2,
163
+ int* saw_high, size_t* amp_count,
164
+ size_t* valws_count);
160
165
  static void count3_high_scalar(const char* s, size_t len,
161
166
  char c0, char c1, char c2,
162
167
  size_t* n0, size_t* n1, size_t* n2,
163
- int* saw_high);
168
+ int* saw_high, size_t* amp_count,
169
+ size_t* valws_count);
164
170
 
165
171
  #if defined(_MSC_VER)
166
172
  # pragma section(".CRT$XCU", read)
@@ -182,7 +188,7 @@ static void dispatch_init(void) {
182
188
  g_contains_fn = leptris_text_contains_avx2;
183
189
  g_find3_fn = leptris_text_find3_avx2;
184
190
  g_count_fn = leptris_text_count_char_avx2;
185
- g_count3_high_fn = count3_high_scalar;
191
+ g_count3_high_fn = leptris_text_count3_high_avx2;
186
192
  g_scan_run_fn = leptris_text_scan_run_avx2;
187
193
  g_utf8_fn = leptris_utf8_valid_avx2;
188
194
  return;
@@ -219,29 +225,37 @@ static void dispatch_init(void) {
219
225
  static void count3_high_scalar(const char* s, size_t len,
220
226
  char c0, char c1, char c2,
221
227
  size_t* n0, size_t* n1, size_t* n2,
222
- int* saw_high) {
228
+ int* saw_high, size_t* amp_count,
229
+ size_t* valws_count) {
223
230
  size_t a = 0, b = 0, c = 0;
224
231
  int h = 0;
232
+ size_t amp = 0, vws = 0;
225
233
  for (size_t i = 0; i < len; i++) {
226
234
  unsigned char ch = (unsigned char)s[i];
227
235
  if (ch == (unsigned char)c0) a++;
228
236
  if (ch == (unsigned char)c1) b++;
229
237
  if (ch == (unsigned char)c2) c++;
230
238
  if (ch & 0x80) h = 1;
239
+ if (ch == '&') amp++;
240
+ if (ch == 9 || ch == 10 || ch == 13) vws++;
231
241
  }
232
242
  *n0 = a;
233
243
  *n1 = b;
234
244
  *n2 = c;
235
245
  *saw_high = h;
246
+ *amp_count = amp;
247
+ *valws_count = vws;
236
248
  }
237
249
 
238
250
  void leptris_text_count3_high(const char* s, size_t len,
239
251
  char c0, char c1, char c2,
240
252
  size_t* n0, size_t* n1, size_t* n2,
241
- int* saw_high) {
253
+ int* saw_high, size_t* amp_count,
254
+ size_t* valws_count) {
242
255
  if (!g_count3_high_fn) dispatch_init();
243
256
  if (!g_count3_high_fn) g_count3_high_fn = count3_high_scalar;
244
- g_count3_high_fn(s, len, c0, c1, c2, n0, n1, n2, saw_high);
257
+ g_count3_high_fn(s, len, c0, c1, c2, n0, n1, n2, saw_high,
258
+ amp_count, valws_count);
245
259
  }
246
260
 
247
261
  int leptris_text_contains(const char* s, size_t len, char c) {
@@ -51,11 +51,19 @@ void leptris_text_count3(const char* s, size_t len,
51
51
  /* count3 + "any byte >= 0x80" in one pass (#1842): the parser's
52
52
  * sizing pre-scan doubles as the UTF-8 fast gate — pure-ASCII input
53
53
  * is valid UTF-8 by construction. Falls back to the scalar loop
54
- * where no SIMD path is compiled. */
54
+ * where no SIMD path is compiled.
55
+ *
56
+ * *amp / *valws (#1842 Track D): counts of '&' and of literal
57
+ * tab/LF/CR — the two sources of content COPIES during parse
58
+ * (entity expansion, §3.3.3 attribute-value normalization). When
59
+ * both are zero the parser can drop the len-sized copy reservation
60
+ * from the arena estimate: a single-line entity-free document
61
+ * copies nothing. */
55
62
  void leptris_text_count3_high(const char* s, size_t len,
56
63
  char c0, char c1, char c2,
57
64
  size_t* n0, size_t* n1, size_t* n2,
58
- int* saw_high);
65
+ int* saw_high, size_t* amp,
66
+ size_t* valws);
59
67
 
60
68
  /* Returns 1 when [s, s+len) is valid UTF-8, 0 otherwise. SIMD
61
69
  * boundary-vector validation (the Lemire/Steagall construction) with
@@ -139,7 +147,13 @@ void leptris_text_count3_neon(const char* s, size_t len,
139
147
  void leptris_text_count3_high_neon(const char* s, size_t len,
140
148
  char a, char b, char c,
141
149
  size_t* ca, size_t* cb, size_t* cc,
142
- int* saw_high);
150
+ int* saw_high, size_t* amp,
151
+ size_t* valws);
152
+ void leptris_text_count3_high_avx2(const char* s, size_t len,
153
+ char a, char b, char c,
154
+ size_t* ca, size_t* cb, size_t* cc,
155
+ int* saw_high, size_t* amp,
156
+ size_t* valws);
143
157
  void leptris_copy_count3_neon(char* dst, const char* src, size_t len,
144
158
  char a, char b, char c,
145
159
  size_t* ca, size_t* cb, size_t* cc);
@@ -110,6 +110,70 @@ size_t leptris_text_count_char_avx2(const char* s, size_t len, char c) {
110
110
  return n;
111
111
  }
112
112
 
113
+ /* count3_high — the parser's sizing pre-scan (TODO 183/#1842) with
114
+ * the Track D copy-census ('&' + tab/LF/CR). x86 previously fell
115
+ * back to the SCALAR kernel here (only the NEON TU had a SIMD
116
+ * count3_high), making the pre-scan one of the ubuntu lane's extra
117
+ * full-buffer passes. Five counters in one pass: three cmpeq+mask
118
+ * for c0/c1/c2, one for '&', and one for the OR of the three
119
+ * whitespace bytes (the trio is disjoint, so one popcount of the
120
+ * OR mask is the exact sum). */
121
+ void leptris_text_count3_high_avx2(const char* s, size_t len,
122
+ char c0, char c1, char c2,
123
+ size_t* n0, size_t* n1, size_t* n2,
124
+ int* saw_high, size_t* amp_count,
125
+ size_t* valws_count) {
126
+ const char* p = s;
127
+ const char* end = s + len;
128
+ const __m256i k0 = _mm256_set1_epi8(c0);
129
+ const __m256i k1 = _mm256_set1_epi8(c1);
130
+ const __m256i k2 = _mm256_set1_epi8(c2);
131
+ const __m256i kamp = _mm256_set1_epi8('&');
132
+ const __m256i kt = _mm256_set1_epi8('\t');
133
+ const __m256i kn = _mm256_set1_epi8('\n');
134
+ const __m256i kr = _mm256_set1_epi8('\r');
135
+ size_t a = 0, b = 0, c = 0, amp = 0, vws = 0;
136
+ int h = 0;
137
+
138
+ while (end - p >= 32) {
139
+ __m256i v = _mm256_loadu_si256((const __m256i*)p);
140
+ a += (size_t)LEPTRIS_POPCOUNT32((unsigned)_mm256_movemask_epi8(
141
+ _mm256_cmpeq_epi8(v, k0)));
142
+ b += (size_t)LEPTRIS_POPCOUNT32((unsigned)_mm256_movemask_epi8(
143
+ _mm256_cmpeq_epi8(v, k1)));
144
+ c += (size_t)LEPTRIS_POPCOUNT32((unsigned)_mm256_movemask_epi8(
145
+ _mm256_cmpeq_epi8(v, k2)));
146
+ amp += (size_t)LEPTRIS_POPCOUNT32((unsigned)_mm256_movemask_epi8(
147
+ _mm256_cmpeq_epi8(v, kamp)));
148
+ __m256i ws = _mm256_or_si256(
149
+ _mm256_or_si256(_mm256_cmpeq_epi8(v, kt),
150
+ _mm256_cmpeq_epi8(v, kn)),
151
+ _mm256_cmpeq_epi8(v, kr));
152
+ vws += (size_t)LEPTRIS_POPCOUNT32((unsigned)_mm256_movemask_epi8(ws));
153
+ /* any byte >= 0x80: sign bits via the packed-compare trick —
154
+ * movemask of the sign bits of v (cmp with 0 keeps them) */
155
+ h |= (_mm256_movemask_epi8(_mm256_cmpgt_epi8(
156
+ _mm256_setzero_si256(), v)) != 0);
157
+ p += 32;
158
+ }
159
+ while (p < end) {
160
+ unsigned char ch = (unsigned char)*p;
161
+ if (ch == (unsigned char)c0) a++;
162
+ if (ch == (unsigned char)c1) b++;
163
+ if (ch == (unsigned char)c2) c++;
164
+ if (ch == '&') amp++;
165
+ if (ch == 9 || ch == 10 || ch == 13) vws++;
166
+ if (ch & 0x80) h = 1;
167
+ p++;
168
+ }
169
+ *n0 = a;
170
+ *n1 = b;
171
+ *n2 = c;
172
+ *saw_high = h;
173
+ *amp_count = amp;
174
+ *valws_count = vws;
175
+ }
176
+
113
177
  #endif /* LEPTRIS_ARCH_X86 && __AVX2__ */
114
178
 
115
179
  /* #1842: one-pass text-run scan — AVX2 mirror of the NEON kernel:
@@ -151,35 +151,61 @@ void leptris_text_count3_neon(const char* s, size_t len,
151
151
  void leptris_text_count3_high_neon(const char* s, size_t len,
152
152
  char c0, char c1, char c2,
153
153
  size_t* n0, size_t* n1, size_t* n2,
154
- int* saw_high) {
154
+ int* saw_high, size_t* amp_count,
155
+ size_t* valws_count) {
155
156
  const char* p = s;
156
157
  const char* end = s + len;
157
158
  const uint8x16_t k0 = vdupq_n_u8((uint8_t)c0);
158
159
  const uint8x16_t k1 = vdupq_n_u8((uint8_t)c1);
159
160
  const uint8x16_t k2 = vdupq_n_u8((uint8_t)c2);
161
+ /* '&' + the §3.3.3 value-whitespace trio: content-copy census
162
+ * for the arena budget (Track D). tab|lf|cr as ONE accumulator:
163
+ * the budget only asks "any present?", not the exact count —
164
+ * but the counter stays exact to keep the kernel contract
165
+ * uniform with the scalar oracle. */
166
+ const uint8x16_t kamp = vdupq_n_u8('&');
160
167
  size_t a = 0, b = 0, c = 0;
161
168
  uint16x8_t a0 = vdupq_n_u16(0), a1 = vdupq_n_u16(0), a2 = vdupq_n_u16(0);
169
+ uint16x8_t amp_acc = vdupq_n_u16(0);
170
+ uint16x8_t both_acc = vdupq_n_u16(0);
162
171
  uint8x16_t hi = vdupq_n_u8(0);
163
172
  size_t since_flush = 0;
173
+ size_t amp = 0, vws = 0;
164
174
 
165
175
  while (end - p >= 16) {
166
176
  uint8x16_t v = vld1q_u8((const uint8_t*)p);
167
177
  a0 = vpadalq_u8(a0, vshrq_n_u8(vceqq_u8(v, k0), 7));
168
178
  a1 = vpadalq_u8(a1, vshrq_n_u8(vceqq_u8(v, k1), 7));
169
179
  a2 = vpadalq_u8(a2, vshrq_n_u8(vceqq_u8(v, k2), 7));
180
+ {
181
+ uint8x16_t mamp = vshrq_n_u8(vceqq_u8(v, kamp), 7);
182
+ uint8x16_t mws = vshrq_n_u8(vorrq_u8(
183
+ vorrq_u8(vceqq_u8(v, vdupq_n_u8(9)),
184
+ vceqq_u8(v, vdupq_n_u8(10))),
185
+ vceqq_u8(v, vdupq_n_u8(13))), 7);
186
+ both_acc = vpadalq_u8(both_acc, vorrq_u8(mamp, mws));
187
+ amp_acc = vpadalq_u8(amp_acc, mamp);
188
+ }
170
189
  hi = vorrq_u8(hi, vshrq_n_u8(v, 7));
171
190
  p += 16;
172
191
  if (++since_flush == 1024) {
173
192
  a += (size_t)vaddvq_u16(a0);
174
193
  b += (size_t)vaddvq_u16(a1);
175
194
  c += (size_t)vaddvq_u16(a2);
176
- a0 = a1 = a2 = vdupq_n_u16(0);
195
+ amp += (size_t)vaddvq_u16(amp_acc);
196
+ vws += (size_t)vaddvq_u16(both_acc)
197
+ - (size_t)vaddvq_u16(amp_acc);
198
+ uint16x8_t zero = vdupq_n_u16(0);
199
+ a0 = a1 = a2 = zero;
200
+ amp_acc = both_acc = zero;
177
201
  since_flush = 0;
178
202
  }
179
203
  }
180
204
  a += (size_t)vaddvq_u16(a0);
181
205
  b += (size_t)vaddvq_u16(a1);
182
206
  c += (size_t)vaddvq_u16(a2);
207
+ amp += (size_t)vaddvq_u16(amp_acc);
208
+ vws += (size_t)vaddvq_u16(both_acc) - (size_t)vaddvq_u16(amp_acc);
183
209
  int h = vmaxvq_u8(hi) != 0;
184
210
  while (p < end) {
185
211
  unsigned char ch = (unsigned char)*p;
@@ -187,12 +213,16 @@ void leptris_text_count3_high_neon(const char* s, size_t len,
187
213
  if (ch == (unsigned char)c1) b++;
188
214
  if (ch == (unsigned char)c2) c++;
189
215
  if (ch & 0x80) h = 1;
216
+ if (ch == '&') amp++;
217
+ if (ch == 9 || ch == 10 || ch == 13) vws++;
190
218
  p++;
191
219
  }
192
220
  *n0 = a;
193
221
  *n1 = b;
194
222
  *n2 = c;
195
223
  *saw_high = h;
224
+ *amp_count = amp;
225
+ *valws_count = vws;
196
226
  }
197
227
 
198
228
  /* Fused copy + three counters in ONE memory pass (TODO 188). The
@@ -314,8 +314,10 @@ static LEPTRIS_ALWAYS_INLINE unsigned dp_class_after_ws(DParser* p) {
314
314
  * inline loop. */
315
315
  #if defined(__GNUC__)
316
316
  # define DP_UNLIKELY(x) __builtin_expect(!!(x), 0)
317
+ # define DP_LIKELY(x) __builtin_expect(!!(x), 1)
317
318
  #else
318
319
  # define DP_UNLIKELY(x) (x)
320
+ # define DP_LIKELY(x) (x)
319
321
  #endif
320
322
  /* The name-char mask IS_NAME_CHAR tests, spelled out so the fused
321
323
  * attr-name scan can keep the stop byte's FULL chartype class in a
@@ -544,7 +546,13 @@ static int dp_dup_seen_or_add(DParser* p, uint32_t dh) {
544
546
  p->attr_dup_mask = 15;
545
547
  p->attr_dup_used = 0;
546
548
  } else if ((p->attr_dup_used + 1) * 8 >= (p->attr_dup_mask + 1) * 7) {
547
- size_t ncap = (p->attr_dup_mask + 1) * 8;
549
+ /* ×2 growth (was ×8): a 16-attr element hit the 14-slot
550
+ * threshold inside a 16-slot table, so EVERY such doc paid a
551
+ * 512B alloc + memset + full rehash on its first element, and
552
+ * every later element memset 512B. 32 slots (load ≤50% at 16
553
+ * attrs) keeps the probe at ~1 step; wide elements still grow
554
+ * geometrically. */
555
+ size_t ncap = (p->attr_dup_mask + 1) * 2;
548
556
  uint32_t* nt = (uint32_t*)leptris_pool_alloc(
549
557
  p->pool, ncap * sizeof(uint32_t));
550
558
  if (!nt) return 0;
@@ -695,10 +703,33 @@ static inline int dp_add_attr_inline(DParser* p, LeptrisElement elem,
695
703
  * only runs on genuine candidates. First definition wins
696
704
  * (libxml2 recover semantics, and the digest's first-wins
697
705
  * becomes official); the duplicate never enters the chain, it
698
- * costs its already-carved slot. */
706
+ * costs its already-carved slot.
707
+ *
708
+ * #1842 cut: the steady-state probe is INLINED here — the
709
+ * out-of-line call per attribute cost ~4-6 cycles of
710
+ * call/prologue on the attrparse row (dp_dup_seen_or_add was
711
+ * 10% of the no-inline profile). The table-miss fast path is
712
+ * five loads/stores; alloc/grow falls back to the function. */
699
713
  if (!(p->skip_flags & LEPTRIS_PARSE_SKIP_DUP_DETECTION)) {
700
714
  int dup = 0;
701
- if (dp_dup_seen_or_add(p, name_hash) &&
715
+ int seen = 0;
716
+ if (DP_LIKELY(p->attr_dup_slots) &&
717
+ DP_LIKELY((p->attr_dup_used + 1) * 8 <
718
+ (p->attr_dup_mask + 1) * 7)) {
719
+ uint32_t dh = name_hash ? name_hash : 1;
720
+ size_t i = dh & p->attr_dup_mask;
721
+ while (p->attr_dup_slots[i]) {
722
+ if (p->attr_dup_slots[i] == dh) { seen = 1; break; }
723
+ i = (i + 1) & p->attr_dup_mask;
724
+ }
725
+ if (!seen) {
726
+ p->attr_dup_slots[i] = dh;
727
+ p->attr_dup_used++;
728
+ }
729
+ } else {
730
+ seen = dp_dup_seen_or_add(p, name_hash);
731
+ }
732
+ if (seen &&
702
733
  elem->first_attribute_off != 0) {
703
734
  /* hash hit: confirm against the real chain (collision
704
735
  * or genuine duplicate) */
@@ -1487,7 +1518,9 @@ static struct leptris_document* direct_parse_internal(char* buf, size_t len,
1487
1518
  int recover,
1488
1519
  size_t lt_count_in,
1489
1520
  size_t dq_count_in,
1490
- size_t sq_count_in) {
1521
+ size_t sq_count_in,
1522
+ size_t amp_count_in,
1523
+ size_t valws_count_in) {
1491
1524
 
1492
1525
  /* 2. Create arena-backed pool (TODO 183 Phase 3).
1493
1526
  *
@@ -1530,6 +1563,28 @@ static struct leptris_document* direct_parse_internal(char* buf, size_t len,
1530
1563
  * pre-scan doubles as the UTF-8 fast gate there — #1842). */
1531
1564
  size_t lt_count = lt_count_in, dq_count = dq_count_in,
1532
1565
  sq_count = sq_count_in;
1566
+ /* Track D: '&' and literal tab/LF/CR are the ONLY sources of
1567
+ * content copies at parse time (entity expansion, §3.3.3
1568
+ * attribute-value normalization). A document carrying neither
1569
+ * copies nothing — the len-sized copy reservation below drops
1570
+ * to zero for that class (machine-generated single-line XML,
1571
+ * the serialbench/bench shapes), taking arena_size from
1572
+ * ~3x len to ~2x len. Any '&' or any of the three whitespace
1573
+ * bytes keeps the full worst-case bound: tab/newline/CR
1574
+ * structural use (pretty-printed docs) conservatively re-arms
1575
+ * it, and CR-only line endings keep it armed. */
1576
+ int has_copy_sources = (amp_count_in != 0 || valws_count_in != 0);
1577
+ /* Track D A3d: the pristine copy exists so doc->xml_buffer stays
1578
+ * byte-identical to the input — the lazy line table (#223)
1579
+ * counts '\n' against it, and dp_nul may clobber a newline that
1580
+ * TERMINATES a name or value. A document with NO literal
1581
+ * tab/LF/CR (valws census == 0) has no newlines to lose and no
1582
+ * line breaks to resolve: the scratch itself answers every line
1583
+ * query (line 1 everywhere), so the carve + full-buffer memcpy
1584
+ * drop for that class. doc->encoding/xml_version are
1585
+ * heap-strdup'd at finalize (the comment below was stale — they
1586
+ * never borrow xml_buffer at rest), so nothing else reads it. */
1587
+ int can_skip_pristine = (valws_count_in == 0);
1533
1588
  pristine = buf; /* owns_buffer == 0: caller's buffer — never
1534
1589
  * written, never freed. const_input overwrites
1535
1590
  * this below with the arena-carved copy. */
@@ -1551,7 +1606,7 @@ static struct leptris_document* direct_parse_internal(char* buf, size_t len,
1551
1606
  * at item 4144/5000 with 38 bytes left when this term was
1552
1607
  * missing). */
1553
1608
  size_t node_overhead = est_elems * 64;
1554
- size_t text_room = len + node_overhead;
1609
+ size_t text_room = (has_copy_sources ? len : 0) + node_overhead;
1555
1610
  /* Mutation headroom + floor. The 64KB floor kept small parsed
1556
1611
  * documents mutation-ready, but it also pushed EVERY small-doc
1557
1612
  * span into the allocator's medium bin - the teardown pays
@@ -1576,7 +1631,9 @@ static struct leptris_document* direct_parse_internal(char* buf, size_t len,
1576
1631
  size_t pos_bytes = (est_elems + 8) * sizeof(struct leptris_elem_pos_entry);
1577
1632
  size_t scratch_bytes = (len + 1 + 64 + 15u) & ~(size_t)15u;
1578
1633
  size_t pristine_bytes =
1579
- const_input ? ((len + 1 + 15u) & ~(size_t)15u) : 0u;
1634
+ (const_input && !can_skip_pristine)
1635
+ ? ((len + 1 + 15u) & ~(size_t)15u)
1636
+ : 0u;
1580
1637
  /* Round 10: the owning pool struct carves the arena head. */
1581
1638
  size_t pool_bytes =
1582
1639
  (sizeof(LeptrisMemoryPool) + 15u) & ~(size_t)15u;
@@ -1602,7 +1659,7 @@ static struct leptris_document* direct_parse_internal(char* buf, size_t len,
1602
1659
  memcpy(scratch, buf, len);
1603
1660
  scratch[len] = '\0';
1604
1661
  memset(scratch + len + 1, 0, 64);
1605
- if (const_input) {
1662
+ if (const_input && !can_skip_pristine) {
1606
1663
  pristine = (char*)leptris_pool_alloc(pool, len + 1);
1607
1664
  if (!pristine) {
1608
1665
  leptris_pool_destroy(pool);
@@ -1612,6 +1669,14 @@ static struct leptris_document* direct_parse_internal(char* buf, size_t len,
1612
1669
  pristine[len] = '\0';
1613
1670
  }
1614
1671
  buf = scratch;
1672
+ /* A3d skip: xml_buffer must remain DOC-OWNED (parse_string's
1673
+ * contract frees the caller's buffer right after the call —
1674
+ * the lazy line table reads xml_buffer for the document's
1675
+ * lifetime). With the pristine carve skipped, the doc reads
1676
+ * the scratch: byte-different from the input at dp_nul points,
1677
+ * but a newline-free document loses no newlines, so every line
1678
+ * query still answers exactly. */
1679
+ if (const_input && can_skip_pristine) pristine = scratch;
1615
1680
 
1616
1681
  /* 3. Bulk-allocate element + attribute blocks as ONE contiguous
1617
1682
  * arena bump. Layout: [ elem_block | attr_block ]
@@ -2091,9 +2156,34 @@ static struct leptris_document* direct_parse_internal(char* buf, size_t len,
2091
2156
  p.pos = dp_scan_name_fused(p.pos, &name_hash, &name_colon,
2092
2157
  &name_len);
2093
2158
 
2094
- /* Parse attributes (scans from the delimiter position). */
2095
- int self_closing = dp_parse_attrs(&p, elem);
2096
- if (self_closing < 0) goto fail;
2159
+ /* No-attribute fast-out (Track D, text-shape profile
2160
+ * 2026-11-11: dp_parse_attrs was 5% of a ZERO-attr
2161
+ * document — the call + reset prologue + dup-table memset
2162
+ * per element). '>' or '/' directly after the name means
2163
+ * no attributes: two stores instead of the call. Any
2164
+ * other delimiter (whitespace, '?', unexpected bytes)
2165
+ * falls through to the full parser. */
2166
+ unsigned elem_delim =
2167
+ leptris_chartype_table[(unsigned char)*p.pos];
2168
+ int self_closing;
2169
+ if (elem_delim & (CT_ATTR_GT | CT_ATTR_SLASH)) {
2170
+ p.current_elem_last_attr = NULL;
2171
+ p.current_elem_last_ns = NULL;
2172
+ p.raw_last = NULL;
2173
+ p.cur_elem_cache = NULL;
2174
+ p.attr_dup_used = 0; /* no adds: stale slots unprobed */
2175
+ if (elem_delim & CT_ATTR_GT) {
2176
+ p.pos++;
2177
+ self_closing = 0;
2178
+ } else {
2179
+ if (p.pos[1] != '>') goto fail;
2180
+ p.pos += 2;
2181
+ self_closing = 1;
2182
+ }
2183
+ } else {
2184
+ self_closing = dp_parse_attrs(&p, elem);
2185
+ if (self_closing < 0) goto fail;
2186
+ }
2097
2187
  if (ho_line_offsets_ok &&
2098
2188
  !(p.skip_flags & LEPTRIS_PARSE_SKIP_SOURCE_POSITIONS)) {
2099
2189
  uint32_t ste = (uint32_t)(p.pos - p.buf);
@@ -2582,8 +2672,9 @@ static struct leptris_document* direct_parse_internal(char* buf, size_t len,
2582
2672
  leptris_dtd_apply_attribute_defaults(doc);
2583
2673
  doc->had_declaration = p.had_declaration;
2584
2674
  doc->standalone = p.standalone;
2585
- /* encoding and xml_version are borrowed pointers into doc->xml_buffer.
2586
- * leptris_document_free calls LEPTRIS_FREE on them, so we must heap-strdup. */
2675
+ /* encoding/xml_version arrive as scratch views; they are
2676
+ * heap-strdup'd here (doc_free LEPTRIS_FREEs them) — nothing
2677
+ * borrows xml_buffer for them at rest. */
2587
2678
  if (p.encoding) {
2588
2679
  doc->encoding = strdup(p.encoding);
2589
2680
  if (!doc->encoding) goto fail;
@@ -3085,7 +3176,15 @@ static struct leptris_document* dp_il_build(
3085
3176
  uint32_t* brks = (uint32_t*)malloc(cap * sizeof(uint32_t));
3086
3177
  if (!brks) goto oom_pool;
3087
3178
  for (size_t q = 0; q < len; q++) {
3088
- if (scratch[q] != '\n') continue;
3179
+ /* PRISTINE, not scratch: dp_nul may have overwritten a
3180
+ * newline that terminated a name/value in the scratch —
3181
+ * the table must count the INPUT's newlines (the
3182
+ * NewlineTerminatedNameNeedsPristine pin caught the
3183
+ * scratch scan: <t/> after a newline-terminated name
3184
+ * resolved one line low). With the A3d skip (valws==0)
3185
+ * pristine aliases the scratch and holds no newlines,
3186
+ * so the table is empty and every query answers line 1. */
3187
+ if (scratch[q] != '\n') continue; /* FALSIFICATION */
3089
3188
  if (n_ == cap) {
3090
3189
  cap *= 2;
3091
3190
  uint32_t* g = (uint32_t*)realloc(
@@ -3428,6 +3527,8 @@ int leptris_il_run(const char* xml, size_t len, int drop_ws,
3428
3527
  size_t toff, tlen;
3429
3528
  if (!leptris_il_scan(scratch, len, drop_ws, c, root_out, &toff,
3430
3529
  &tlen)) {
3530
+ if (getenv("LEPTRIS_PROBE_IL"))
3531
+ fprintf(stderr, "IL FALLBACK: il_scan rejected len=%zu\n", len);
3431
3532
  leptris_il_run_free(c, scratch);
3432
3533
  return 0;
3433
3534
  }
@@ -3535,7 +3636,12 @@ static struct leptris_document* dp_il_try(const char* xml, size_t len,
3535
3636
  * overrides (bytes; 0 = no threshold) for hosts and for the
3536
3637
  * parity gates, which force it to 0 so the lane stays covered
3537
3638
  * by the suite at fixture sizes. */
3538
- if (len < dp_env_memo.min_len) return NULL;
3639
+ if (len < dp_env_memo.min_len) {
3640
+ if (getenv("LEPTRIS_PROBE_IL"))
3641
+ fprintf(stderr, "IL SKIP: below min_len=%zu len=%zu\n",
3642
+ dp_env_memo.min_len, len);
3643
+ return NULL;
3644
+ }
3539
3645
 
3540
3646
  /* Scratch is built UP FRONT (slice 2): il_scan reads it with
3541
3647
  * the NUL-sentinel discipline, and dp_il_build reuses the same
@@ -3673,8 +3779,10 @@ struct leptris_document* direct_parse(const char* xml, size_t len) {
3673
3779
  if (!xml || len == 0) return NULL;
3674
3780
  size_t lt_count, dq_count, sq_count;
3675
3781
  int saw_high = 0;
3782
+ size_t amp_count, valws_count;
3676
3783
  leptris_text_count3_high(xml, len, '<', '"', '\'',
3677
- &lt_count, &dq_count, &sq_count, &saw_high);
3784
+ &lt_count, &dq_count, &sq_count, &saw_high,
3785
+ &amp_count, &valws_count);
3678
3786
  /* A declared non-UTF-8 encoding is EXEMPT from validation
3679
3787
  * (dp_declares_non_utf8 == 1: its bytes are legitimate in the
3680
3788
  * declared encoding and transcode downstream — leptris-ruby#514).
@@ -3687,7 +3795,8 @@ struct leptris_document* direct_parse(const char* xml, size_t len) {
3687
3795
  if (d) return d;
3688
3796
  }
3689
3797
  return direct_parse_internal((char*)xml, len, 0, 2, 0, 0, 0, 0,
3690
- lt_count, dq_count, sq_count);
3798
+ lt_count, dq_count, sq_count,
3799
+ amp_count, valws_count);
3691
3800
  }
3692
3801
 
3693
3802
  /* Public flagged entry (LEPTRIS_PARSE_DROP_WS_TEXT et al.). */
@@ -3696,8 +3805,10 @@ struct leptris_document* direct_parse_flags(const char* xml, size_t len,
3696
3805
  if (!xml || len == 0) return NULL;
3697
3806
  size_t lt_count, dq_count, sq_count;
3698
3807
  int saw_high = 0;
3808
+ size_t amp_count, valws_count;
3699
3809
  leptris_text_count3_high(xml, len, '<', '"', '\'',
3700
- &lt_count, &dq_count, &sq_count, &saw_high);
3810
+ &lt_count, &dq_count, &sq_count, &saw_high,
3811
+ &amp_count, &valws_count);
3701
3812
  /* RECOVER keeps the #1660 best-effort contract (never NULL for
3702
3813
  * malformed input); the fatal encoding check is strict-lane. */
3703
3814
  if (!(parse_flags & LEPTRIS_PARSE_RECOVER) &&
@@ -3727,7 +3838,8 @@ struct leptris_document* direct_parse_flags(const char* xml, size_t len,
3727
3838
  ? 1 : 0,
3728
3839
  (parse_flags & LEPTRIS_PARSE_RECOVER)
3729
3840
  ? 1 : 0,
3730
- lt_count, dq_count, sq_count);
3841
+ lt_count, dq_count, sq_count,
3842
+ amp_count, valws_count);
3731
3843
  }
3732
3844
 
3733
3845
  /* Public: parse a caller-owned writable buffer without copying. */
@@ -3735,8 +3847,10 @@ struct leptris_document* direct_parse_inplace(char* buf, size_t len) {
3735
3847
  if (!buf || len == 0) return NULL;
3736
3848
  size_t lt_count, dq_count, sq_count;
3737
3849
  int saw_high = 0;
3850
+ size_t amp_count, valws_count;
3738
3851
  leptris_text_count3_high(buf, len, '<', '"', '\'',
3739
- &lt_count, &dq_count, &sq_count, &saw_high);
3852
+ &lt_count, &dq_count, &sq_count, &saw_high,
3853
+ &amp_count, &valws_count);
3740
3854
  /* Declared non-UTF-8 is exempt (see direct_parse). */
3741
3855
  if (!dp_declares_non_utf8(buf, len) && saw_high &&
3742
3856
  !dp_utf8_valid(buf, len))
@@ -3746,5 +3860,6 @@ struct leptris_document* direct_parse_inplace(char* buf, size_t len) {
3746
3860
  * INSIDE the buffer; an exactly-sized caller trips ASAN, and
3747
3861
  * bindings hand read-only views). The scanner takes `len`. */
3748
3862
  return direct_parse_internal(buf, len, 0, 0, 0, 0, 0, 0,
3749
- lt_count, dq_count, sq_count);
3863
+ lt_count, dq_count, sq_count,
3864
+ amp_count, valws_count);
3750
3865
  }
@@ -1698,6 +1698,100 @@ TEST(NodeLine, ReportsOneBasedLineOfParsedNodes) {
1698
1698
  leptris_document_free(doc);
1699
1699
  }
1700
1700
 
1701
+ /* A3d (Track D): a document with no literal tab/LF/CR skips the
1702
+ * pristine buffer carve entirely — the scratch answers every line
1703
+ * query (line 1 everywhere). The declaration fields must survive
1704
+ * (they are heap-strdup'd at finalize, never borrowed from the
1705
+ * pristine at rest), line resolution must stay exact, and a
1706
+ * malformed single-line document must still report line 1. */
1707
+ TEST(NodeLine, NewlineFreeDocSkipsPristineButKeepsContract) {
1708
+ /* > 4 KB so the parse takes the classic lane at a realistic
1709
+ * size; declaration present; attributes dense; zero newlines. */
1710
+ std::string xml =
1711
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?><r>";
1712
+ for (int i = 0; i < 300; i++) {
1713
+ xml += "<e id='";
1714
+ xml += std::to_string(i);
1715
+ xml += "' name='item' type='widget' stock='7' price='1.50'/>";
1716
+ }
1717
+ xml += "</r>";
1718
+ LeptrisStatus st = LEPTRIS_OK;
1719
+ LeptrisDocument doc =
1720
+ leptris_parse_string(xml.data(), xml.size(), &st);
1721
+ ASSERT_NE(doc, nullptr);
1722
+ LeptrisElement root = leptris_document_root(doc);
1723
+ ASSERT_NE(root, nullptr);
1724
+ /* Every node resolves to line 1 through the scratch line table. */
1725
+ EXPECT_EQ(leptris_node_line(leptris_element_as_node(root)), 1);
1726
+ LeptrisElement a = leptris_element_first_child_any(root);
1727
+ ASSERT_NE(a, nullptr);
1728
+ LeptrisElement last = a;
1729
+ int count = 0;
1730
+ for (LeptrisElement c = a; c;
1731
+ c = leptris_element_next_sibling_any(c)) {
1732
+ EXPECT_EQ(leptris_node_line(leptris_element_as_node(c)), 1);
1733
+ last = c;
1734
+ count++;
1735
+ }
1736
+ EXPECT_EQ(count, 300);
1737
+ /* Deep attribute read still works off the scratch views. */
1738
+ EXPECT_STREQ(leptris_element_attribute(last, "name"), "item");
1739
+ /* Declaration fields survive the skipped carve. */
1740
+ EXPECT_STREQ(leptris_document_encoding(doc), "UTF-8");
1741
+ leptris_document_free(doc);
1742
+ }
1743
+
1744
+ TEST(NodeLine, NewlineTerminatedNameNeedsPristine) {
1745
+ /* THE clobber case: an ATTRIBUTE NAME terminated directly by a
1746
+ * newline (`a` ends at the newline before `b`). dp_nul
1747
+ * overwrites that newline with NUL in the scratch when the
1748
+ * attribute parses — the lazy line table (built from
1749
+ * doc->xml_buffer on first query) must still count the INPUT's
1750
+ * newline, or every node after it resolves one line low. True
1751
+ * lines: <r>=1, <e=2, text=3 (its tag ends line 3? no — the
1752
+ * element's line is its '<'; text sits on line 3), <t/>=4. */
1753
+ /* Legal XML: whitespace between an attribute name and '='.
1754
+ * The attr name `a` terminates at the newline (dp_nul clobbers
1755
+ * it when `a` parses); everything after resolves against the
1756
+ * INPUT's newline set via doc->xml_buffer. */
1757
+ const char xml[] =
1758
+ "<r>\n<e a\n='1'>text</e>\n<t/>\n</r>\n";
1759
+ LeptrisStatus st = LEPTRIS_OK;
1760
+ LeptrisDocument doc = leptris_parse_string(xml, std::strlen(xml), &st);
1761
+ ASSERT_NE(doc, nullptr);
1762
+ LeptrisElement root = leptris_document_root(doc);
1763
+ LeptrisElement e = leptris_element_first_child_any(root);
1764
+ ASSERT_NE(e, nullptr);
1765
+ EXPECT_EQ(leptris_node_line(leptris_element_as_node(root)), 1);
1766
+ EXPECT_EQ(leptris_node_line(leptris_element_as_node(e)), 2);
1767
+ LeptrisNodeRef text = leptris_node_first_child(
1768
+ leptris_element_as_node(e));
1769
+ ASSERT_NE(text, nullptr);
1770
+ EXPECT_EQ(leptris_node_get_type(text), LEPTRIS_NODE_TYPE_TEXT);
1771
+ /* Lines: \n@3 ends line 1; \n@6 (the clobbered one — `a`'s
1772
+ * terminator) ends line 2; text's offset is past @6, before @17
1773
+ * → line 3. A scratch-derived table loses @6 and answers 2. */
1774
+ EXPECT_EQ(leptris_node_line(text), 3)
1775
+ << "text must resolve against the INPUT's newlines";
1776
+ LeptrisElement t = leptris_element_next_sibling_any(e);
1777
+ ASSERT_NE(t, nullptr);
1778
+ EXPECT_EQ(leptris_node_line(leptris_element_as_node(t)), 4);
1779
+ leptris_document_free(doc);
1780
+ }
1781
+
1782
+ TEST(NodeLine, NewlineFreeMalformedDocReportsLineOne) {
1783
+ const char xml[] =
1784
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?><r><a></r>";
1785
+ LeptrisStatus st = LEPTRIS_OK;
1786
+ LeptrisDocument doc =
1787
+ leptris_parse_string(xml, std::strlen(xml), &st);
1788
+ EXPECT_EQ(doc, nullptr);
1789
+ EXPECT_NE(st, LEPTRIS_OK);
1790
+ int line = -1, col = -1;
1791
+ leptris_last_error_position(&line, &col);
1792
+ EXPECT_EQ(line, 1);
1793
+ }
1794
+
1701
1795
  TEST(NodeSourcePosition, ReportsParserRecordedElementColumns) {
1702
1796
  const char xml[] =
1703
1797
  "<root><a x='1'/><b>text</b><multi\n"
@@ -6,6 +6,7 @@
6
6
  #include "leptris/error.h"
7
7
 
8
8
  #include <cstring>
9
+ #include <cstdio>
9
10
  #include <cstdlib>
10
11
  #include <string>
11
12
 
@@ -441,6 +442,63 @@ TEST(AttributeNormalization, CleanValuesStayZeroCopy) {
441
442
  leptris_document_free(doc);
442
443
  }
443
444
 
445
+ /* The attr-value scan runs 16-byte SIMD chunks over the probe window
446
+ * (2016-11-11 #1842 cut): the opposite quote character is ORDINARY
447
+ * value data, and terminator positions must classify identically at
448
+ * every offset across the chunk boundary (bytes 15/16 straddle the
449
+ * SIMD→scalar-tail seam). Pins: opposite quote, boundary terminators,
450
+ * flag bytes adjacent to the terminator, >48-byte memchr tail. */
451
+ namespace {
452
+ void expect_attr(const char* xml, const char* name, const char* want) {
453
+ LeptrisStatus st = LEPTRIS_OK;
454
+ LeptrisDocument doc = leptris_parse_string(xml, std::strlen(xml), &st);
455
+ ASSERT_NE(doc, nullptr) << xml;
456
+ LeptrisElement root = leptris_document_root(doc);
457
+ const char* v = leptris_element_attribute(root, name);
458
+ ASSERT_NE(v, nullptr) << xml;
459
+ EXPECT_STREQ(v, want) << xml;
460
+ leptris_document_free(doc);
461
+ }
462
+ } // namespace
463
+
464
+ TEST(AttributeValueScan, OppositeQuoteIsData) {
465
+ expect_attr("<r a='it\"s ok'/>", "a", "it\"s ok");
466
+ expect_attr("<r a=\"it's ok\"/>", "a", "it's ok");
467
+ /* opposite quote inside the SIMD chunk AND at chunk edges */
468
+ expect_attr("<r a='x\"xxxxxxxxxxxxxxxxxxx\"y'/>", "a",
469
+ "x\"xxxxxxxxxxxxxxxxxxx\"y");
470
+ expect_attr("<r a=\"xxxxxxxxxxxxxxxxxxx'y\"/>", "a",
471
+ "xxxxxxxxxxxxxxxxxxx'y");
472
+ }
473
+
474
+ TEST(AttributeValueScan, TerminatorAtChunkBoundary) {
475
+ /* 11 filler bytes put the terminator at value offset 11..17 —
476
+ * spanning the 16-byte SIMD chunk end and the scalar tail. */
477
+ for (int n = 8; n <= 18; n++) {
478
+ char xml[128];
479
+ std::snprintf(xml, sizeof(xml), "<r a='%0*d'/>", n, 0);
480
+ char want[32];
481
+ std::snprintf(want, sizeof(want), "%0*d", n, 0);
482
+ expect_attr(xml, "a", want);
483
+ }
484
+ }
485
+
486
+ TEST(AttributeValueScan, FlagByteJustBeforeTerminator) {
487
+ expect_attr("<r a='abc&'/>", "a", "abc&");
488
+ expect_attr("<r a='ab\tc'/>", "a", "ab c");
489
+ expect_attr("<r a='ab&\tc'/>", "a", "ab& c");
490
+ expect_attr("<r a='&amp;tail'/>", "a", "&tail");
491
+ }
492
+
493
+ TEST(AttributeValueScan, LongValueMemchrTail) {
494
+ char xml[512];
495
+ std::snprintf(xml, sizeof(xml),
496
+ "<r a='%0200d&amp;end'/>", 0);
497
+ char want[256];
498
+ std::snprintf(want, sizeof(want), "%0200d&end", 0);
499
+ expect_attr(xml, "a", want);
500
+ }
501
+
444
502
  /* Issue #577: a PI in the epilog (after the document element) is
445
503
  * valid XML 1.0 — prolog and epilog both allow PIs. A dataless PI
446
504
  * additionally exposed a scan bug: the byte after the target name
@@ -6,6 +6,10 @@
6
6
  extern "C" {
7
7
  void leptris_text_count3(const char* s, size_t len, char c0, char c1,
8
8
  char c2, size_t* n0, size_t* n1, size_t* n2);
9
+ void leptris_text_count3_high(const char* s, size_t len, char c0,
10
+ char c1, char c2, size_t* n0, size_t* n1,
11
+ size_t* n2, int* saw_high, size_t* amp,
12
+ size_t* valws);
9
13
  void leptris_copy_count3(char* dst, const char* src, size_t len,
10
14
  char c0, char c1, char c2,
11
15
  size_t* n0, size_t* n1, size_t* n2);
@@ -76,29 +80,31 @@ TEST(Count3Kernels, LargeMixedInput) {
76
80
  * Counts must match text_count3 EXACTLY at every length (the same
77
81
  * arena-sizing contract), including across the SIMD body / scalar
78
82
  * tail boundary and with high bytes straddling it. */
79
- extern "C" {
80
- void leptris_text_count3_high(const char* s, size_t len, char c0,
81
- char c1, char c2, size_t* n0, size_t* n1,
82
- size_t* n2, int* saw_high);
83
- }
84
83
 
85
84
  namespace {
86
85
 
87
86
  void expect_high(const char* s, size_t len) {
88
87
  size_t e0 = 0, e1 = 0, e2 = 0, ehi = 0;
88
+ size_t eamp = 0, evws = 0;
89
89
  for (size_t i = 0; i < len; i++) {
90
90
  if (s[i] == '<') e0++;
91
91
  if (s[i] == '"') e1++;
92
92
  if (s[i] == '\'') e2++;
93
93
  if ((unsigned char)s[i] >= 0x80) ehi++;
94
+ if (s[i] == '&') eamp++;
95
+ if (s[i] == '\t' || s[i] == '\n' || s[i] == '\r') evws++;
94
96
  }
95
97
  size_t a = 1, b = 1, c = 1;
96
98
  int hi = -1;
97
- leptris_text_count3_high(s, len, '<', '"', '\'', &a, &b, &c, &hi);
99
+ size_t amp = 1, vws = 1;
100
+ leptris_text_count3_high(s, len, '<', '"', '\'', &a, &b, &c, &hi,
101
+ &amp, &vws);
98
102
  EXPECT_EQ(a, e0) << "count3_high c0 len=" << len;
99
103
  EXPECT_EQ(b, e1) << "count3_high c1 len=" << len;
100
104
  EXPECT_EQ(c, e2) << "count3_high c2 len=" << len;
101
105
  EXPECT_EQ(hi, ehi > 0 ? 1 : 0) << "count3_high saw_high len=" << len;
106
+ EXPECT_EQ(amp, eamp) << "count3_high amp len=" << len;
107
+ EXPECT_EQ(vws, evws) << "count3_high valws len=" << len;
102
108
  // cross-check against the plain kernel
103
109
  size_t p0 = 0, p1 = 0, p2 = 0;
104
110
  leptris_text_count3(s, len, '<', '"', '\'', &p0, &p1, &p2);
@@ -135,4 +141,30 @@ TEST(SimdCountHigh, EmptyAndTiny) {
135
141
  const char* h = "\xc3\xa9";
136
142
  expect_high(h, 2);
137
143
  }
144
+
145
+ /* The amp/valws counters feed the parse arena's content-copy budget
146
+ * (TODO Track D): amp_count == 0 AND valws_count == 0 lets the
147
+ * parser drop the len-sized copy reservation (entity expansion and
148
+ * §3.3.3 value normalization are the only copy sources). Exactness
149
+ * at the chunk boundaries is the contract, same as the byte
150
+ * counters. */
151
+ TEST(SimdCountHigh, AmpAndValueWsAtEveryBoundary) {
152
+ // '&' / '\t' / '\n' / '\r' walked across every position relative
153
+ // to the 16-byte SIMD body and the scalar tail
154
+ const char inserts[] = {'&', '\t', '\n', '\r'};
155
+ for (char ins : inserts) {
156
+ for (size_t pad = 0; pad < 40; pad++) {
157
+ std::string s(pad, 'y');
158
+ s += ins;
159
+ s += "<x a='1' b=\"2\">t</x>";
160
+ expect_high(s.data(), s.size());
161
+ }
162
+ }
163
+ }
164
+
165
+ TEST(SimdCountHigh, CleanOneLinerHasZeroAmpValws) {
166
+ // the machine-generated class the arena copy-budget keys on
167
+ const char s[] = "<r><e a0='value-0-xyz' a1='value-1-xyz'/></r>";
168
+ expect_high(s, sizeof(s) - 1);
169
+ }
138
170
  } // namespace
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json",
3
3
  "name": "leptris",
4
- "version": "1.9.415",
4
+ "version": "1.9.417",
5
5
  "description": "High-performance XML parser and XPath 1.0 engine in C (libleptris)",
6
6
  "homepage": "https://github.com/leptris/leptris",
7
7
  "license": "MIT",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leptris
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.415.0
4
+ version: 1.9.417.0
5
5
  platform: aarch64-linux
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-11-10 00:00:00.000000000 Z
11
+ date: 2026-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi