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

Cache common Primer values #197

Merged
merged 2 commits into from Feb 8, 2021
Merged

Cache common Primer values #197

merged 2 commits into from Feb 8, 2021

Conversation

BlakeWilliams
Copy link
Contributor

@BlakeWilliams BlakeWilliams commented Feb 8, 2021

  • Add Primer::Classify::Cache class for preloading common primer classes
  • Use Primer::Classify::Cache when available in Primer::Classify
  • Add benchmark tests to avoid having to give imprecise counts due to
    differences in Ruby/Rails versions
  • Add CI for running benchmarks against Rails main, Ruby 2.7
  • Only run simplecov if COVERAGE=1 in your environment

This takes us from 114 allocations when not cached, down to 40 allocations when cached. There's probably a lot more work that could be done here, like catching new keys that Classify supports and tracking that we're caching them correctly.

Co-authored with @kenyonj

@vercel
Copy link

vercel bot commented Feb 8, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/primer/view-components/9bflmlg23
✅ Preview: https://view-components-git-bmw-jk-classify-hashify.primer.vercel.app

@vercel vercel bot temporarily deployed to Preview February 8, 2021 19:21 Inactive
@vercel vercel bot temporarily deployed to Preview February 8, 2021 19:33 Inactive
@vercel vercel bot temporarily deployed to Preview February 8, 2021 19:35 Inactive
@vercel vercel bot temporarily deployed to Preview February 8, 2021 19:39 Inactive
@vercel vercel bot temporarily deployed to Preview February 8, 2021 19:41 Inactive
@vercel vercel bot temporarily deployed to Preview February 8, 2021 19:45 Inactive
@vercel vercel bot temporarily deployed to Preview February 8, 2021 20:10 Inactive
@vercel vercel bot temporarily deployed to Preview February 8, 2021 20:23 Inactive
@vercel vercel bot temporarily deployed to Preview February 8, 2021 20:25 Inactive
@vercel vercel bot temporarily deployed to Preview February 8, 2021 20:30 Inactive
* Add benchmark tests to avoid having to give imprecise counts due to
  differences in Ruby/Rails versions
* Add CI for running benchmarks against Rails main, Ruby 2.7
* Only run simplecov if `COVERAGE=1` in your environment

Co-authored-by: Justin Kenyon <kenyonj@github.com>
@vercel vercel bot temporarily deployed to Preview February 8, 2021 20:34 Inactive
@BlakeWilliams BlakeWilliams marked this pull request as ready for review February 8, 2021 20:38
@BlakeWilliams
Copy link
Contributor Author

Here's the benchmark results as well:

Screen Shot 2021-02-08 at 3 31 55 PM

Copy link
Contributor

@joelhawksley joelhawksley left a comment

Choose a reason for hiding this comment

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

🤯 Next level work here, Blake and Justin! Dang!


preload(
keys: [Primer::Classify::COLOR_KEY, Primer::Classify::BG_KEY],
values: [:blue, :gray_dark, :gray, :gray_light, :red, :orange, :orange_light, :yellow, :green, :purple, :white, :pink]
Copy link
Contributor

Choose a reason for hiding this comment

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

How did you arrive on these values here? (And for the rest of this file?) I'd love to have a process to ensure this optimization stays up to date 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was very unscientific, we went through https://primer.style/css/ and tried to find colors to fill in here 😅.

There's probably a few better ways to handle it, like maybe parsing primer itself for color variables that we could use but we didn't have time to look into anything like that.

@vercel vercel bot temporarily deployed to Preview February 8, 2021 21:00 Inactive
@BlakeWilliams BlakeWilliams merged commit 00b5b7a into main Feb 8, 2021
@BlakeWilliams BlakeWilliams deleted the bmw-jk/classify-hashify branch February 8, 2021 21:07
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.

None yet

2 participants