Closed mgirlich closed 10 months ago
@hadley It would be great to get your opinion of whether this approach is fine for you. It kind of works against the dispatch system. But I'm also not quite sure whether the dispatch is really needed as there are only three classes (
The performance gains are quite big (around a factor of 20), which would be nice for e.g. the {paws} package (a package to work with AWS).
Overall, the code is pretty redundant so we could also use a macro or some other CPP techniques but I'm not so familiar with C/CPP to know about the potential downsides.
This breaks fhircracker
setClass(
Class = "fhir_bundle_xml",
contains = c("fhir_resource_xml", "fhir_bundle"),
slots = c(next_link = "fhir_url", self_link = "fhir_url"),
prototype = prototype(xml2::read_xml(x = "<Bundle></Bundle>"))
)
I'm guessing this is because while inherits(x, "xml_node")
is still true, Rf_inherits()
doesn't handle S4 classes.
Yeah — looks like it https://github.com/wch/r-source/blob/d6dad605b05810cb43f991d292169a2cd436a818/src/include/Rinlinedfuns.h#L774.
Closes #386.
Created on 2023-08-23 with reprex v2.0.2
More benchmarks
``` r library(xml2) data <- read_xml("http://aiweb.cs.washington.edu/research/projects/xmltk/xmldata/data/courses/reed.xml") many_elts <- data |> xml_contents() |> xml_contents() |> xml_contents() path <- xml2_example("cd_catalog.xml") xml <- read_xml(path) cds <- xml |> xml_children() cd_contents <- cds |> xml_contents() bench::mark( cds = xml_name(cds), cd_contents = xml_name(cd_contents), many_elts = xml_name(many_elts), check = FALSE ) #> # A tibble: 3 × 6 #> expression min median `itr/sec` mem_alloc `gc/sec` #>