Skip to content

Profile ggplot2 and grid performance #2701

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

Closed
dpseidel opened this issue Jun 14, 2018 · 6 comments
Closed

Profile ggplot2 and grid performance #2701

dpseidel opened this issue Jun 14, 2018 · 6 comments

Comments

@dpseidel
Copy link
Collaborator

No description provided.

@dpseidel
Copy link
Collaborator Author

dpseidel commented Jul 9, 2018

mirror of grid
external repository of profiling results

@tmastny and I are interested in pulling together a list of potential avenues of attack for improving grid and ggplot2 performance, additional links/issues/ideas/discussion are appreciated.

Currently open issues identify these two areas for improvement:

@clauswilke
Copy link
Member

There are two parts to grid in the way we use it: (i) construction of grobs; (ii) rendering of grobs. I have looked primarily at part (i), but I have some ideas for part (ii) also.

For part (i), I see extensive room for speed improvement. Most importantly, units, grobs, and gpars are all rather simple data structures, and grid uses a large amount of code to generate them. If one wrote lightweight code to generate them, maybe even in C++, one could get a significant speed boost. I provided an example here.

It might also be useful to write special-purpose unit functions, e.g. the equivalent of:

unit_pt <- function(x) unit(x, "pt")

but implemented directly in C++.

For part (ii), I noticed how complex the drawing code is that gets called when we do grid.draw(x). There are no special-purpose functions for commonly used grobs such as points or text. As a consequence, for example, we call makeContent.default() and makeContext.default() on every points grob, even though these functions do nothing. It looks to me like there's significant room for improvement there as well.

@tmastny
Copy link

tmastny commented Jul 10, 2018

ggplot's geom_path also seems significantly slower than base and lattice line plots. Here's an example from this profile:
image

@paleolimbot
Copy link
Member

I know @thomasp85 has implemented a bit of this...the previous work is really cool! I put that test suite into the (very experimental) ggdebug package as ggbench() (which wraps around the bench package):

# remotes::install_github("paleolimbot/ggdebug")
library(ggdebug)
ggbench()
#> Warning: Some expressions had a GC in every iteration; so filtering is
#> disabled.
#> # A tibble: 4 x 7
#>   stage  expression      min   median `itr/sec` mem_alloc `gc/sec`
#>   <fct>  <bch:expr> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 spec   basic       970.1µs      1ms    963.      1.95MB     21.6
#> 2 build  basic        8.61ms   9.09ms    108.      3.54MB     26.2
#> 3 draw   basic       27.82ms  31.96ms     31.9     2.97MB     87.8
#> 4 render basic      109.94ms 117.77ms      8.68   978.7KB     13.9

plot(ggbench(ggbench_standards(which = NULL)))
#> Warning: Some expressions had a GC in every iteration; so filtering is
#> disabled.

#> Warning: Some expressions had a GC in every iteration; so filtering is
#> disabled.

#> Warning: Some expressions had a GC in every iteration; so filtering is
#> disabled.
#> Loading required namespace: tidyr

Created on 2019-06-25 by the reprex package (v0.2.1)

@thomasp85
Copy link
Member

I think we can safely close this issue

@lock
Copy link

lock bot commented Dec 28, 2019

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Dec 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants