Add FlatNode: read-only columnar full-DOM reader (#82)#84
Merged
Conversation
The fourth reader alongside Node/LazyNode/Cursor: parse(xml, FlatNode) materializes the whole document once into a contiguous store of isbits records (parent/first_child/next_sibling index links, zero-copy byte ranges into the retained source), so building is fast, random access is O(1), and the GC traces a handful of arrays instead of one object per node. Text and attribute values are entity-decoded at access (the has_entities token flag rides the sign bit of the stored length). The builder is the same single visibly-pushdown pass as _parse with the same well-formedness checks at the same token points (shared check functions; identical error messages, asserted by the parity tests). FlatNode == / hash are positional identity — same store, same node (the #83 semantics, debuting on the new reader). Node(flatnode) materializes a subtree as a mutable Node; XML.write accepts FlatNode. O(1) parent and O(depth) 1-arg depth come free from the stored links. Assisted-by: Claude (Anthropic)
The new W3C parity testset asserts FlatNode ≡ Node (decoded trees) on every well-formed document of the pinned conformance suite, and the exact same accept/reject verdict on every not-well-formed one — any divergence between the flat builder and _parse is a named failure. It caught exactly one on first run, on 5 documents (sun/invalid/empty.xml, oasis p15pass1/p18pass1, ibm P15/P20): an empty comment <!----> or CDATA <![CDATA[]]> has value "" on Node but came back nothing on FlatNode, because the record encoded absence as len == 0. Absence is now value_offset == -1 (empty content keeps a real offset with len 0), matching the Node parser on all three states: absent, empty, present. Assisted-by: Claude (Anthropic)
Assisted-by: Claude (Anthropic)
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## v0.5-dev #84 +/- ##
============================================
+ Coverage 94.47% 94.76% +0.28%
============================================
Files 11 12 +1
Lines 1793 2026 +233
============================================
+ Hits 1694 1920 +226
- Misses 99 106 +7
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements #82 —
FlatNode, the fourth reader:parse(xml, FlatNode)materializes the whole document once into a contiguous store of isbits records (index links + zero-copy byte ranges into the retained source; text/attribute values entity-decoded at access).Node's read half atCursor's GC cost.Measured in-package on the 13.5 MiB XMark corpus (882k nodes): build 51.6 ms / 35.5 MiB alloc vs
Node117.3 ms / 122.3 MiB — 2.3× faster, 3.4× fewer allocations, matching the validated prototype; GC pressure collapses (the collector traces a handful of arrays instead of ~2.5 objects per node).Guarantees, all test-enforced:
Nodeparser: decoded-equivalent trees on all 776 well-formed documents; identical accept/reject verdicts on all 1257 not-well-formed ones. The parity harness caught (and this PR fixes) one real divergence on first run: empty<!---->/<![CDATA[]]>must be"", notnothing(tri-state record: absent / empty / present).wellformedlevels and identical error messages asparse(_, Node).==/hashonFlatNodeare positional identity (same store, same node) — the Node identity: === and hash redesign (planned for v0.5) #83 semantics, debuting on the new reader;unique/Dictbehave.parent(node), O(depth) 1-argdepth(node);Node(flatnode)materializes a subtree as a mutableNode;XML.writeacceptsFlatNode.typemax(Int32)guard (clear error pointing atNode).Also adds the reader-orientation table to the README (the four readers behind one accessor set). Targets
v0.5-dev.