Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AshesITR opened this issue Dec 20, 2023 · 0 comments
Open

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

AshesITR opened this issue Dec 20, 2023 · 0 comments
Labels
internals Issues related to inner workings of lintr, i.e., not user-visible performance

Comments

@AshesITR
Copy link
Collaborator

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)

@MichaelChirico MichaelChirico added performance internals Issues related to inner workings of lintr, i.e., not user-visible labels Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internals Issues related to inner workings of lintr, i.e., not user-visible performance
Projects
None yet
Development

No branches or pull requests

2 participants