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

perf(core): improve applyVariants method speed #1790

Merged
merged 2 commits into from Oct 22, 2022
Merged

Conversation

AndreyYolkin
Copy link
Contributor

@AndreyYolkin AndreyYolkin commented Oct 21, 2022

thanks First of all, I want to thank you for the brilliant framework. While I interested of how it works I started looking into sources.

I found that applyVariants method could be improved a bit, but it helps to reach 7x speed supremacy over windicss:

  • instead of chaining reduce() and reduce() methods we can simply write reduceRight(), as result will be the same (+ original array does not mutate)
  • we may use variantHandlers.slice() instead of [...variantHandlers] as it 2x faster (according to jsbench.me).

I think there are a lot of other possibilities to improve the performance, but I think it's a nice start

@netlify
Copy link

netlify bot commented Oct 21, 2022

Deploy Preview for unocss ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit a852217
🔍 Latest deploy log https://app.netlify.com/sites/unocss/deploys/6352dfd0a0ef7e00083d9fea
😎 Deploy Preview https://deploy-preview-1790--unocss.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@AndreyYolkin AndreyYolkin changed the title perf(core): slice variantHandlers instead of destructuring perf(core): improve applyVariants method speed Oct 21, 2022
zyyv
zyyv approved these changes Oct 22, 2022
@antfu antfu merged commit b546af5 into unocss:main Oct 22, 2022
11 checks passed
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

3 participants