.data pronoun speedup - #5731
Merged
Merged
Conversation
teunbrand
commented
Feb 29, 2024
|
|
||
| extract_target_is_likely_data <- function(x, data, env) { | ||
| if (!is.name(x[[2]])) { | ||
| if (!is.name(x[[2]]) || identical(x[[2]], quote(.data))) { |
Collaborator
Author
There was a problem hiding this comment.
Couldn't find anything in rlang like is_pronoun() so we only escape .data here and not .env. I don't think .env is very common.
thomasp85
approved these changes
Feb 29, 2024
thomasp85
left a comment
Member
There was a problem hiding this comment.
LGTM
This is perhaps the most efficient diff in terms of character changed to performance gained :-)
Contributor
|
Thanks! You were extremely fast at fixing this! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR aims to fix #5730.
Briefly, using the
.datapronoun caused the plot to slow down by a non-trivial amount of time. This PR rectifies this by considering the pronoun as 'non-data'. To explain a bit further, here follows the diagnosis.unrowname()throws errors with pronouns:Created on 2024-02-29 with reprex v2.1.0
And
unrowname()is used to compare to see if a part of an expression evaluates to the plot data here:ggplot2/R/aes.R
Lines 437 to 440 in bc3e401
As this is in a
tryCatch()block, the errors thatunrowname()throws for pronouns are silenced. However, formatting the error message is still relatively expensive.In this PR, we circumvent this problem by recognising that the
.datapronoun is not the same as the regular plot data, thereby bypassing the check in the lines above.As a benchmark, we see that typical evaluation and with pronoun are in the same range with this PR:
Created on 2024-02-29 with reprex v2.1.0
For reference, this is the same benchmark result, but on the current main branch: