Skip to content

Use farver for colour transformations - #224

Merged
hadley merged 19 commits into
masterfrom
farver
Nov 4, 2019
Merged

hadley merged 19 commits into
masterfrom
farver

Conversation

@hadley

@hadley hadley commented Oct 25, 2019 •

Copy link
Copy Markdown
Member

Fixes #223

  • Update all tests with exact colours
  • Replace convertColor() calls
  • Rewrite col2hcl()
  • Replace all other uses of grDevices
  • Create benchmark for color_ramp() vs colorRamp()

@hadley

hadley commented Oct 31, 2019

Copy link
Copy Markdown
Member Author

Unfortunately this change makes colour_ramp() slower than colorRamp(), at least in R3.6:

x <- seq(0, 1, length = 1e5)
col <- c("red", "green", "blue")

bench::mark(
  base = grDevices::rgb(colorRamp(col)(x), maxColorValue = 255)
)
#> # A tibble: 1 x 6
#>   expression      min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 base         17.2ms   21.9ms      45.3    19.4MB     34.0
bench::mark(
  scales = scales::colour_ramp(col)(x)
)
#> # A tibble: 1 x 6
#>   expression      min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr> <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 scales       49.5ms   51.4ms      19.4    36.7MB     58.3

Created on 2019-10-31 by the reprex package (v0.3.0)

I did a little profiling and the bottleneck is primarily in the matrix manip in col2rgb() and rgb2col() so I'm confident the performance will improve drastically once those functions are implemented natively in farver.

@hadley
hadley marked this pull request as ready for review October 31, 2019 16:07
@hadley

hadley commented Oct 31, 2019

Copy link
Copy Markdown
Member Author

Oh it's also slower in R 3.5 with cran scales, so I don't think this is a new change, and I don't have any hesitation to merge this PR as is.

@hadley
hadley requested a review from thomasp85 October 31, 2019 16:15

@thomasp85 thomasp85 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - should I prioritise farver to get it updated before scales submission?

@hadley
hadley merged commit eb24db7 into master Nov 4, 2019
@hadley
hadley deleted the farver branch November 4, 2019 13:11
@hadley

hadley commented Nov 4, 2019

Copy link
Copy Markdown
Member Author

@thomasp85 I don't think you need to prioritise it; if it happens, it happens.

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.

Use farver for colour ramp

2 participants