Skip to content

Conversation

@MichaelChirico
Copy link
Collaborator

  1. Pull declaration of the .transformer function outside the for (cl in glue_calls) loop
  2. Use the .envir environment to remove the dependency of the .transformer on globals inside extract_glued_symbols
  3. Operate directly on the getParseData() output for this symbol case rather than converting to XML and then searching an XPath
  4. Use names(env) over ls(env, all.names=TRUE) which I found is somehow 20x faster

I tried testing the performance on dplyr, but it's mostly using glue() unqualified, so I haven't had any luck yet. We might try loosening that restriction.

@MichaelChirico
Copy link
Collaborator Author

Benchmark-ish. Did a find-and-replace in one dplyr file for glue( --> glue::glue( to ensure object_usage_linter() is actually evaluating glue() calls. Then ran lint() 40 times:

# on main
system.time(replicate(40, simplify=FALSE, lint("dplyr/R/join-by.R", object_usage_linter())))
#     user  system elapsed
#   63.096   0.331  63.701

# on this branch
system.time(replicate(40, simplify=FALSE, lint("dplyr/R/join-by.R", object_usage_linter())))
#     user  system elapsed
#   59.484   0.204  59.891

So a small speed-up (5-6%) in typical usages. It should be a lot better in pathological cases (especially a {...} expression with a lot of variables)

Comment on lines +194 to +201
if (is.null(parsed_text)) {
return("")
}
parse_data <- utils::getParseData(parsed_text)
# covers NULL & NA cases
if (nrow(parse_data) == 0L) {
return("")
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there existing tests indirectly covering the two conditionals here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I defer to codecov :)

if (nrow(parse_data) == 0L) {
return("")
}
symbols <- parse_data$text[parse_data$token == "SYMBOL"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this approach differentiate between x and `x`?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I think it doesn't, but neither did the old approach.

@codecov-commenter
Copy link

Codecov Report

Merging #1612 (7158f06) into main (8f9d1cc) will decrease coverage by 0.01%.
The diff coverage is 86.66%.

@@            Coverage Diff             @@
##             main    #1612      +/-   ##
==========================================
- Coverage   95.07%   95.06%   -0.02%     
==========================================
  Files          98       98              
  Lines        4390     4393       +3     
==========================================
+ Hits         4174     4176       +2     
- Misses        216      217       +1     
Impacted Files Coverage Δ
R/object_usage_linter.R 92.65% <86.66%> (-0.45%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@IndrajeetPatil IndrajeetPatil merged commit 560b40d into main Oct 6, 2022
@IndrajeetPatil IndrajeetPatil deleted the glue-loop branch October 6, 2022 05:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants