Repository navigation
feat!: overhaul rxml for shared-reference performance and strict XML correctness - #15
Merged
Merged
Conversation
…correctness Bump crate to 2.5.0. Node.children and search results now return shared references (Vec<Py<Node>> internally) instead of deep-copying subtrees on every Python attribute access, and parsing/serialization release the GIL (py.detach) so multithreaded callers can parse/write in parallel. Benchmarked on a 1.72 MB / ~36k-node document (median of 5): tree traversal 60 ms -> 17.5 ms (~3.4x), search 22 ms -> 0.5 ms (~40x); parse/write times unchanged (+/-5%) despite the correctness work below. Parsing now builds a plain RawNode tree off-GIL and converts it to Python objects once. The read path uses quick-xml's borrowed read_event() instead of per-recursion-level buffers; the write path drops a full-buffer copy and streams through BufWriter instead of building the whole output string. Release profile adds lto = "thin", codegen-units = 1, strip = true. Correctness fixes: - Malformed XML (mismatched/unclosed tags, invalid attributes, unknown entity refs) now raises ValueError with a byte position via a typed ParseError enum, instead of a Rust panic. Missing file raises FileNotFoundError; missing root tag raises ValueError instead of returning an empty node. - Entities are unescaped on read (text via GeneralRef event accumulation, attributes via spec XML attribute-value normalization). The writer escapes tab/CR/LF in attribute values as character references so documents round-trip losslessly (previously they silently corrupted to spaces). - Elements nested inside a same-named ancestor now parse correctly (the old parser collapsed them; test_read_file encoded this bug and has been corrected). - Multiple text fragments concatenate instead of last-wins, <root/> as root works, and root_tag now matches at any depth (subtree extraction) - documented and tested. - rxml.pyi: Node.text corrected to `str | None`. CHANGELOG.md is removed; release notes now live in GitHub releases, which pyproject.toml's Changelog URL already points to. Test count 11 -> 20 (20/20 passing), clippy --all-targets -D warnings clean, cargo fmt clean. BREAKING CHANGE: Node.children and search results now expose shared node references instead of independent deep copies, so `is`/`id()` identity semantics are observable across accesses. Malformed input raises ValueError/FileNotFoundError instead of a Rust PanicException, and previously-tolerated malformed XML now fails to parse.
Raise the maturin build/dev requirement from >=1.9.6 / >=1.0,<2.0 to >=1.14.1 (dev keeps the <2.0 ceiling). Verified with an isolated `uv build` honoring the new pin, followed by a wheel smoke test. Update README.md to match this branch's behavior changes: Node.text corrected to `str | None`, a note that children/search results are shared references (cheap repeated access), and new feature bullets for GIL-released parse/write (thread parallelism) and ValueError with position info / FileNotFoundError on malformed or missing input.
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.
Performance and correctness overhaul of the rxml PyO3 extension, bumping the crate from 2.4.1 to 3.0.0. Reviewed by a full code-review pass (approved, no outstanding findings); 20/20 Rust tests passing;
cargo clippy --all-targets -D warningsclean;cargo fmtclean.Python-visible behavior changes (call these out to consumers):
Node.childrenand search results now share references (is/id()identity is observable across accesses) instead of each access returning an independent deep copy.ValueError/FileNotFoundErrorinstead of a RustPanicException.Changes
Node.childrenand search results now returnVec<Py<Node>>internally instead of deep-copying subtrees on every Python attribute access. Benchmarked on a 1.72 MB / ~36k-node XML document (median of 5 runs): Python-side tree traversal 60 ms → 17.5 ms (~3.4x), search 22 ms → 0.5 ms (~40x).py.detach, so multithreaded callers can parse/write in parallel. Parsing builds a plainRawNodetree off-GIL and converts it to Python objects once.read_event()instead of allocating a buffer per recursion level; the write path drops a full-buffer copy and streams throughBufWriterinstead of building the entire output string in memory.lto = "thin",codegen-units = 1,strip = true. Parse/write times are unchanged (±5%) despite the correctness work below.ValueErrorwith a byte position via a typedParseErrorenum, instead of a Rust panic. A missing file raisesFileNotFoundError; a missing root tag raisesValueErrorinstead of silently returning an empty node.GeneralRefevent accumulation, attributes via spec XML attribute-value normalization). The writer escapes tab/CR/LF in attribute values as character references so documents round-trip losslessly (previously these characters silently corrupted to spaces).test_read_fileencoded this bug and has been corrected).<root/>as a root element works;root_tagmatches at any depth (subtree extraction) — documented and tested.rxml.pyi:Node.textcorrected tostr | None.CHANGELOG.mdremoved deliberately — release notes now live in GitHub releases, whichpyproject.toml's Changelog URL already points to. (The notable-changes list above can be reused as release notes.)pyproject.toml: build-systemmaturinrequirement raised to>=1.14.1(dev keeps<2.0), verified with an isolateduv buildand wheel smoke test.README.mdrefreshed to match this branch:Node.textshown asstr | None, a note on shared-reference semantics forchildren/search, and new feature bullets for GIL-released parse/write and the new error types.How to Test
All 20 Rust tests should pass, clippy should be clean, and formatting should be clean.
Notes
RawNodetree, which also underpins the shared-reference change).Checklist
cargo test)cargo fmtandruff format)cargo clippy)