Vectorize xml_find_* helpers - #480
Open
MichaelChirico wants to merge 1 commit 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.
In {lintr}, I found that a natural replacement for the common idiom
xml_text(xml_find_first(x, "XPATH"))isxml_find_chr(x, "string(XPATH)"). This already dramatically reduces the memory footprint, but the R-side looping kills the performance a bit (e.g. 30% slower).This PR proposes vectorizing the whole operation in C(++) instead, providing 10-40x performance improvement and 50-75% memory reduction.
PR prepared by Gemini. There are a number of similar ways to implement the proposal -- filing first to probe interest in maintaining this approach before attempting to fine-tune the details.
Given the apparent "correctness" of using
xml_find_chr(), I will be changing {lintr} to use it anyway -- it would be nice to get the free performance enhancement, too.Benchmark Results
Medium Nodeset ($N = 500$ items)
xml_text(xml_find_first(x, 'name'))xml_find_chr(x, 'string(name)')(OLDvapply)xml_find_chr(x, 'string(name)')(NEW C++)!is.na(xml_find_first(x, 'active[...]'))xml_find_lgl(x, 'boolean(...)')(OLDvapply)xml_find_lgl(x, 'boolean(...)')(NEW C++)xml_find_num(x, 'number(...)')(OLDvapply)xml_find_num(x, 'number(...)')(NEW C++)xml_find_int(x, 'count(...)')(OLDvapply)xml_find_int(x, 'count(...)')(NEW C++)Large Nodeset ($N = 5{,}000$ items)
xml_text(xml_find_first(x, 'name'))xml_find_chr(x, 'string(name)')(OLDvapply)xml_find_chr(x, 'string(name)')(NEW C++)xml_text)~38.9x faster (vs old
xml_find_chr)!is.na(xml_find_first(x, 'active[...]'))xml_find_lgl(x, 'boolean(...)')(OLDvapply)xml_find_lgl(x, 'boolean(...)')(NEW C++)!is.na)~25.0x faster (vs old
xml_find_lgl)xml_find_num(x, 'number(...)')(OLDvapply)xml_find_num(x, 'number(...)')(NEW C++)xml_find_int(x, 'count(...)')(OLDvapply)xml_find_int(x, 'count(...)')(NEW C++)Benchmark script