Skip to content
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

Performance: encode_native() does not need an intermediate character vector #37

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

zeehio
Copy link

@zeehio zeehio commented Sep 18, 2022

This pull request is applied on top of #36 . Please review that first.

We avoid the intermediate character vector when encoding to native. This makes encode_native() much faster.

This is part of tidyverse/ggplot2#4989, aiming to improve the performance of rasterizing large matrices.

library(farver)
x <- runif(1E7)
ramp <- scales::colour_ramp(c("red", "blue"))
colours_chr <- ramp(x)
spectrum <- farver::decode_colour(colours_chr)

bench::mark(
  before = {
    # This was how encode_native worked before
    cols <- encode_colour(spectrum, alpha = 0.75)
    farver:::encode_native(cols)
  },
  after = {
    farver::encode_native(spectrum,alpha = 0.75)
  }
)
#> # A tibble: 2 × 6
#>   expression      min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 before        1.16s    1.16s     0.866   114.5MB     0   
#> 2 after       83.53ms  86.04ms    11.7      38.1MB     2.34

Created on 2022-09-18 by the reprex package (v2.0.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant