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

feat: Speed up get_color_contrast() #1140

Merged
merged 5 commits into from
Nov 25, 2024
Merged

Conversation

gadenbuie
Copy link
Member

@gadenbuie gadenbuie commented Nov 25, 2024

Optimizes get_color_contrast() by avoiding re-using bs_get_contrast() and instead directly creating a small Sass layer with a minimal set of Sass files.

This ends up speeding up get_color_contrast() calls by about 25x:

pkgload::load_all()
#> ℹ Loading bslib

results <- bench::mark(
  before = get_color_contrast_old("blue"),
  after = get_color_contrast("blue"), 
  min_time = 2
)

plot(results)

image

results
#> # 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         29ms  30.57ms      32.3    6.22MB     51.1
#> 2 after         979µs   1.11ms     818.    98.81KB     23.1

@gadenbuie gadenbuie requested a review from cpsievert November 25, 2024 22:08
R/utils.R Outdated Show resolved Hide resolved
gadenbuie and others added 2 commits November 25, 2024 17:13
IDE color preview adds a couple of characters in the row with the color
Copy link
Collaborator

@cpsievert cpsievert left a comment

Choose a reason for hiding this comment

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

Nice, thanks!

@gadenbuie gadenbuie merged commit a6fda93 into main Nov 25, 2024
1 check passed
@gadenbuie gadenbuie deleted the feat/speed-up-get-color-contrast branch November 25, 2024 23:03
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.

2 participants