Skip to content

Prefer parent::* to parent::expr where possible #2497

Open
@AshesITR

Description

@AshesITR

If we know the type of the parent node (or don't care about it), parent::* is faster than parent::expr:

Here is comparison data for

x <- get_source_expressions("https://raw.githubusercontent.com/Rdatatable/data.table/master/inst/tests/tests.Rraw")
xml <- x$expressions[[length(x$expressions)]]$full_xml_parsed_content
system.time(xml_find_all(xml, "//SYMBOL_FUNCTION_CALL/parent::expr"))
#   user  system elapsed 
#   2.02    0.00    2.02 
system.time(xml_find_all(xml, "//SYMBOL_FUNCTION_CALL/parent::expr/parent::expr"))
#   user  system elapsed 
#  3.903   0.000   3.904 
system.time(xml_find_all(xml, "//SYMBOL_FUNCTION_CALL/parent::*"))
#   user  system elapsed 
#  1.989   0.000   1.989 
system.time(xml_find_all(xml, "//SYMBOL_FUNCTION_CALL/parent::*/parent::*"))
#   user  system elapsed 
#  3.877   0.000   3.877 

Originally posted by @AshesITR in #2496 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    internalsIssues related to inner workings of lintr, i.e., not user-visibleperformance

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions