leptris 1.9.415.0 → 1.9.417.0

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.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -1
  3. data/lib/leptris/vendor/aarch64-linux/libleptris.so +0 -0
  4. data/lib/leptris/vendor/aarch64-linux-musl/libleptris.so +0 -0
  5. data/lib/leptris/vendor/arm-linux/libleptris.so +0 -0
  6. data/lib/leptris/vendor/arm-linux-musl/libleptris.so +0 -0
  7. data/lib/leptris/vendor/arm64-darwin/libleptris.dylib +0 -0
  8. data/lib/leptris/vendor/ppc64le-linux/libleptris.so +0 -0
  9. data/lib/leptris/vendor/s390x-linux-musl/libleptris.so +0 -0
  10. data/lib/leptris/vendor/x86_64-darwin/libleptris.dylib +0 -0
  11. data/lib/leptris/vendor/x86_64-linux/libleptris.so +0 -0
  12. data/lib/leptris/vendor/x86_64-linux-musl/libleptris.so +0 -0
  13. data/lib/leptris/version.rb +1 -1
  14. data/vendor-src/README.md +1 -1
  15. data/vendor-src/libleptris/CHANGELOG.md +34 -0
  16. data/vendor-src/libleptris/CMakeLists.txt +1 -1
  17. data/vendor-src/libleptris/README.adoc +73 -17
  18. data/vendor-src/libleptris/TODO.max-perf/15-c-face-vs-pugixml.md +204 -0
  19. data/vendor-src/libleptris/src/include/leptris/dom/document.h +10 -0
  20. data/vendor-src/libleptris/src/leptris/common/simd_text.c +20 -6
  21. data/vendor-src/libleptris/src/leptris/common/simd_text.h +17 -3
  22. data/vendor-src/libleptris/src/leptris/common/simd_text_avx2.c +64 -0
  23. data/vendor-src/libleptris/src/leptris/common/simd_text_neon.c +32 -2
  24. data/vendor-src/libleptris/src/leptris/flat/direct_parse.c +135 -20
  25. data/vendor-src/libleptris/test/dom/test_dom.cpp +94 -0
  26. data/vendor-src/libleptris/test/parser/test_parser.cpp +58 -0
  27. data/vendor-src/libleptris/test/parser/test_simd_count.cpp +38 -6
  28. data/vendor-src/libleptris/vcpkg.json +1 -1
  29. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b05656e6814fe5dcbe135896dcc426daa24d6a9dc5db1ef8f42cf519c1410a9
4
- data.tar.gz: 7bbfd242924fd821500b12931c150bc205ef5a80036cc190fa6f6e63b5481501
3
+ metadata.gz: f52a17d3718decc2997b042e2594f796841cae46478a1aca10db112a598120b1
4
+ data.tar.gz: b8acf6424d421af60934c68ecd86e3618467277588eaf4239ff2c51034895425
5
5
  SHA512:
6
- metadata.gz: e732ab203a32ecdcce58d761975a9111d8cc7d5ceac0fddd27aedd26e391d027297bd4fa8fd150e014805d6cfb63fcc007556d07769b303a78372fdbb8368890
7
- data.tar.gz: a1bbc853d2343e70e9375331db0b1e570c2a06cde6792094701c16533a0cc3b7c0992c05fdfdb05c75b4adaee40fd3fe2c537a3703fff67321342c1ef405f14d
6
+ metadata.gz: 9640eb5dfe475d37ab7df57875fd253022d5f94a7bb5f37ee6fc6d1810d6a8f401345cc8a50ec731d12fc708e564e8a3aa1c950c600b8afeaa622b94ae6f7ad1
7
+ data.tar.gz: 50716f735942431e13eb290f800ff330d96749480c7970b5c51d6e11715da5bb89cd240fae298d62a4fbe44a0bfad3fc4c18e4797e61aeba029c0a6f32ee2b8e
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/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: