⚡ Skip replacing NAs during mapping when appropriate#6344
Merged
Conversation
Collaborator
Author
|
Second benchmark, this time with NAs present: devtools::load_all("~/packages/ggplot2/")
#> ℹ Loading ggplot2
df <- diamonds
set.seed(42)
df$carat[sample(nrow(df), 5)] <- NA
df$price[sample(nrow(df), 50)] <- NA
df$depth[sample(nrow(df), 500)] <- NA
df$table[sample(nrow(df), 5000)] <- NA
p <- ggplot(df, aes(carat, price, colour = depth, size = table)) +
geom_point()
bench::mark(ggplot_build(p), min_iterations = 10)
#> Warning: Some expressions had a GC in every iteration; so filtering is
#> disabled.
#> # A tibble: 1 × 6
#> expression min median `itr/sec` mem_alloc `gc/sec`
#> <bch:expr> <bch:tm> <bch:tm> <dbl> <bch:byt> <dbl>
#> 1 ggplot_build(p) 32.4ms 36ms 14.7 53.9MB 28.0Created on 2025-02-24 with reprex v2.1.1 Same for main: #> # A tibble: 1 × 6
#> expression min median `itr/sec` mem_alloc `gc/sec`
#> <bch:expr> <bch:tm> <bch:tm> <dbl> <bch:byt> <dbl>
#> 1 ggplot_build(p) 40.6ms 43.4ms 13.4 68.7MB 28.2 |
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 replaces #5032.
Briefly, it skips the NA replacment step if there are no NAs present.
Moreover
vec_assign()is faster (and I presume more type stable) thanifelse().I think it is more of an 'empirical' determination than relying on some palette attribute as is proposed in the linked PR.
Benchmarking this PR, note 4 continuous scales (x, y, size, colour):
Created on 2025-02-24 with reprex v2.1.1
The same code on the main branch gives me:
Created on 2025-02-24 with reprex v2.1.1