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
Add test to limit allocations of Primer::Classify
#166
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/primer/view-components/eakj5jko7 |
dd361bc
to
8e4dab3
Compare
I ran some benchmarks testing the new classify vs the classify on
|
memo | ||
end | ||
|
||
def extract_value(memo, key, val, breakpoint) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept these names the same as from before the refactor, but happy to update them to be more descriptive.
test/primer/classify_test.rb
Outdated
values = { align_self: :center, width: :fit, p: 4, m: 1, border: :top, box_shadow: true, color: :red, visibility: :hidden} | ||
Primer::Classify.call(**values) | ||
|
||
assert_allocations 38, within: 4 do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where'd this value of 4
come from? Does this value vary a little in local test vs. CI?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should probably add a comment, but I believe the difference is between Ruby and Rails versions, since we run a matrix of versions in CI.
The other thought was to make a build specifically for testing allocations against 2.7, but I thought I'd submit this as-is and get thoughts/feedback first.
Updated the test to include all, or most of the keys we support. Running the test against |
Call val.to_s.dasherize only when necessary
Replace Hash#except with mutation
Use mutation on `#call` hash instead of `Hash#except`
Convert styles to a string instead of using an array
Replace `.chars.last` with `[-1]`
Separate single value conversion from breakpoint conversion
* change from using regex to using ord comparison * misc. unrelated changes
e80eec8
to
977d0df
Compare
Reduce allocations from 97 to 38 when using a "basic"
Primer::Classify#call
implementation.closes part of #155