Optimize xml_path and xml_find_all for large node sets#478
Open
astruebi wants to merge 2 commits into
Open
Conversation
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.
Closes #477
This PR improves performance for large node sets in two places:
xml_path()now caches reusable ancestor paths while processing anxml_nodeset, avoiding repeated parent walks and repeated construction of shared path prefixes.xml_find_all.xml_node()avoids an unnecessary duplicate pass for single-context XPath node sets and materializesxml_noderesults with less per-node overhead.The intended semantics are unchanged.
Tests added:
xml_path()output is identical to callingxml_path()on each node individuallyxml_find_all()XPath node sets remain unique even for union expressionsImplementation note:
Some repetition in the path occurrence logic is intentional. I tested a more compact shared abstraction for sibling occurrence counting, but it made the hot loop noticeably slower for large node sets. The current version keeps those cases explicit to preserve the performance gain while matching
xmlGetNodePath()semantics.Local checks:
testthat::test_dir("tests/testthat"): PASSR CMD build --no-manual --no-build-vignettes .: OK_R_CHECK_FORCE_SUGGESTS_=false R CMD check --no-manual --no-build-vignettes xml2_1.5.2.tar.gz: OK, with only vignette warnings due to--no-build-vignettes