Replace `structure()` by `class()` by mgirlich · Pull Request #393 · r-lib/xml2 · GitHub
Skip to content

Replace structure() by class()#393

Merged
hadley merged 2 commits into
r-lib:mainfrom
mgirlich:replace-structure-by-class
Jun 29, 2023
Merged

Replace structure() by class()#393
hadley merged 2 commits into
r-lib:mainfrom
mgirlich:replace-structure-by-class

Conversation

@mgirlich

@mgirlich mgirlich commented Jun 1, 2023

Copy link
Copy Markdown

This gives a small performance improvement, e.g. for xml_find_all(flatten = TRUE)

library(xml2)

path <- xml2_example("cd_catalog.xml")
xml <- read_xml(path)
cds <- xml_find_all(xml, "CD")

find <- function() {
  xml_find_all(cds, "TITLE", flatten = FALSE)
}

bench::mark(
  find()
)

# Before
#> # A tibble: 1 × 6
#>   expression      min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 find()        400µs    428µs     2165.    30.3KB     10.3

# After
#> # A tibble: 1 × 6
#>   expression      min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 find()        324µs    360µs     2529.    30.3KB     8.20

Created on 2023-06-01 with reprex v2.0.2

This helps towards #394.

@hadley hadley merged commit f251e92 into r-lib:main Jun 29, 2023
@hadley

hadley commented Jun 29, 2023

Copy link
Copy Markdown
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants