Replies: 2 comments 5 replies
-
Hey @samadadi! 👋 The TLDR is: Generally I'd say tailwind-merge is definitely fast enough for common use cases, but I wouldn't consider it free performance-wise and only use it when I specifically want to merge Tailwind CSS classes. E.g. I wouldn't just replace all my I think if I find some time, I'll create a benchmark for it. But since tailwind-merge relies on caching, it isn't easy to create a test that resembles real-world use. Maybe I'll find an open-source project using it extensively and run the benchmark on that.
tailwind-merge puts most of the stress on the CPU when a lot of components are rendered for the first time ( I just tested this on my computer in the app of https://risecalendar.com where we use // Using tailwind-merge v1.13.0
import { extendTailwindMerge } from 'tailwind-merge'
// This is originally exported as `twMerge`, but I renamed it for this test
export const twMergeInternal = extendTailwindMerge({
// tailwind-merge config
})
let calls = 0
let time = 0
export function twMerge() {
calls += 1
const start = performance.now()
const result = twMergeInternal.apply(null, arguments)
time += performance.now() - start
return result
}
window.setInterval(() => {
console.log('twMerge calls:', calls, 'time:', time)
}, 5000) Results of reloading the app running this code in development mode with Vite on a MacBook Pro 16" with a M1 Pro chip (from 2021) in the Chrome browser with devtools open: 349 calls to |
Beta Was this translation helpful? Give feedback.
-
I think the runtime involvement should be stated somewhere in the doc especially when there is a a when to not use it section here but runtime is not stated. |
Beta Was this translation helpful? Give feedback.
-
Hi. Is there any benchmark that compares twMerge and clsx? Honestly I want to use this library but I want to know how much I am giving up in regard to performance.
Beta Was this translation helpful? Give feedback.
All reactions