Skip to content

.data pronouns slow down plots #5730

Closed
@teunbrand

Description

@teunbrand

This issue is separated from #5729.

Using the .data pronoun is about 20% slower than use normal aesthetics, which seems unreasonable to me.
All the slowdown is in the build stage, not the gtable stage.

library(ggplot2)

p <- ggplot(mtcars) +
  geom_point() +
  facet_grid(gear ~ cyl)

standard <- p + aes(x = mpg, y = disp)
pronoun  <- p + aes(x = .data[["mpg"]], y = .data[["disp"]])

bench::mark(
  ggplot_build(standard),
  ggplot_build(pronoun),
  check = FALSE, min_iterations = 5
)
#> Warning: Some expressions had a GC in every iteration; so filtering is
#> disabled.
#> # A tibble: 2 × 6
#>   expression                  min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr>             <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 ggplot_build(standard)   48.9ms   50.5ms      19.5    6.46MB     60.5
#> 2 ggplot_build(pronoun)    75.4ms   76.8ms      11.6    7.88MB     32.9

standard <- ggplot_build(standard)
pronoun  <- ggplot_build(pronoun)

bench::mark(
  ggplot_gtable(standard),
  ggplot_gtable(pronoun),
  check = FALSE, min_iterations = 5
)
#> # A tibble: 2 × 6
#>   expression                   min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr>              <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 ggplot_gtable(standard)   41.4ms   42.2ms      23.6    3.39MB     70.7
#> 2 ggplot_gtable(pronoun)    42.4ms   43.1ms      23.0  218.79KB     61.4

Created on 2024-02-29 with reprex v2.1.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions