Skip to content

[Performance] Improve tint and shade performance #626

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

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

Conversation

thadeucity
Copy link

Improve the performance of the tint and shade functions.

It is a tiny performance improvement and lib size reduction, but it does not degrade in any shape or form the quality of the code, so I believe it is a welcome change.

The improvement is achieved by exiting the parseToRgb function in the first IF that checks for HEX Colors, this way not testing or matching the default color unnecessarily.

reduce the amount of if checks for default color
reduce the amount of if checks for default color
@thadeucity thadeucity requested a review from bhough as a code owner October 24, 2022 18:29
@codecov
Copy link

codecov bot commented Oct 30, 2022

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (275e646) to head (8b70bb2).
Report is 35 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #626   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           89        89           
  Lines          860       860           
  Branches       323       323           
=========================================
  Hits           860       860           
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@@ -27,7 +27,7 @@ import mix from './mix'

function shade(percentage: number | string, color: string): string {
if (color === 'transparent') return color
return mix(parseFloat(percentage), 'rgb(0, 0, 0)', color)
return mix(parseFloat(percentage), '#000000', color)
Copy link
Contributor

@bhough bhough Oct 30, 2022

Choose a reason for hiding this comment

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

@thadeucity Any reason that we shouldn't send this as a shorthand #000?

Copy link
Author

Choose a reason for hiding this comment

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

The the shorthand one will have two extra Regex validations and two extra if validations (because the first check is for the normal 6 digit hex and the second one is for the 8 digit hex.

@@ -27,7 +27,7 @@ import mix from './mix'

function tint(percentage: number | string, color: string): string {
if (color === 'transparent') return color
return mix(parseFloat(percentage), 'rgb(255, 255, 255)', color)
return mix(parseFloat(percentage), '#FFFFFF', color)
Copy link
Contributor

@bhough bhough Oct 30, 2022

Choose a reason for hiding this comment

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

@thadeucity Same as with mix, should we send the shorthand #fff?

Copy link
Contributor

@bhough bhough left a comment

Choose a reason for hiding this comment

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

Hi @thadeucity, thank you for taking the time to contribute. A couple small changes, and we should be abe to merge this for inclusion in our next release.

@bhough bhough self-assigned this Mar 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants