joe-bell / cva

Class Variance Authority
https://cva.style
Apache License 2.0
5.78k stars 110 forks source link

Feat: Performance enhancements #281

Open fveracoechea opened 6 months ago

fveracoechea commented 6 months ago

Description

Implement code optimizations on CVA to increase execution speed and reduce the number of operations, such as iterations and object copying.

Additional context

Let's say we have a web page made of React components, where most components utilize CVA. Since React components render and re-render often, it's important to keep CVA's runtime overhead as low as possible. This optimization will enhance scalability, especially on large projects.

Benchmark results

pnpx ts-node ./packages/cva/src/benchmark.ts
(index) branch name ops/sec average (ms) samples
0 feat/performance-enhancement 440297 0.002 2201487
1 cva/main 125161 0.008 625810 3.52 x slower

image

All tests passing with no problems:

image

What is the purpose of this pull request?

Before submitting the PR, please make sure you do the following

vercel[bot] commented 6 months ago

@fveracoechea is attempting to deploy a commit to the cva Team on Vercel.

A member of the Team first needs to authorize it.

joe-bell commented 6 months ago

This is super thoughtful of you, thanks @fveracoechea 🙏❤️

Fairly busy at the moment and this will take some time to review, so don't be too disheartened if it takes some time to get around to this! Really appreciate it

fveracoechea commented 6 months ago

Thanks @joe-bell 🙏 let me know if you have any suggestions or concerns, I’d be happy to help!