fix: capture <REQ-IF> opening tag without O(N²) tree mutation#217
Merged
stanislaw merged 1 commit intoJun 11, 2026
Merged
Conversation
17b9383 to
dd2e10a
Compare
stanislaw
reviewed
Jun 10, 2026
stanislaw
reviewed
Jun 10, 2026
stanislaw
left a comment
Contributor
There was a problem hiding this comment.
It is a great change, I just left a small comment.
_parse_reqif recorded the original <REQ-IF ...> opening tag by removing every child of the parsed root and serializing the emptied root. Removing the CORE-CONTENT child forced libxml2 to reconcile namespaces across the whole detached spec-object subtree, making this O(N²) in the number of spec objects (~two-thirds of total parse time on large files). Serialize a shallow copy of the root (same tag, nsmap, attributes, no children) instead. This is non-destructive and linear; output is byte-identical for pretty-printed inputs.
dd2e10a to
1afb4f9
Compare
Contributor
Author
|
fixed. this is an important fix for us. |
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.
ReqIFParser._parse_reqifrecords the original<REQ-IF …>opening tag (its namespace declarations and attributes) for faithful round-trip unparsing. It did this by deleting every childof the parsed root and serializing the now-empty root. Removing the
CORE-CONTENTchild forcedlibxml2to reconcile namespaces across the entire detached spec-object subtree — O(N²) inthe number of spec objects, accounting for roughly two-thirds of total parse time on large files (tens of minutes at 100k objects).
Fix
Serialize a shallow copy of the root (same tag, nsmap, and attrib, no children) instead of mutating the parsed tree.
lxmlhas no API to serialize an element's opening tag alone, so achildless copy is the linear way to isolate it. This is also non-destructive — it removes the prior side effect of emptying the caller's tree.
Behavior
<REQ-IF .../>to<REQ-IF ...>— the correct form for an opening-tag capture; does not occur inpretty-printed files.
Performance
Full parse_from_string is now linear: ~0.17 s at 20k objects and ~0.35 s at 40k, versus the old capture block alone taking ~14 s and ~84 s.
Tests
Unit 49/49 pass; integration 78/79 (the one failure is an environmental missing
libtidy, unrelated).