Closed j-manu closed 1 year ago
Wow, I'd have to profile to see if I'm getting a performance hit for using it. I don't know where I'd memoize it as this isn't being used within an object that instantiates or is a class. Reading a bit more about the gem, I can see why it might be a performance issue to use this on every page load. How did you profile to see the implications of this in production? Happy to combine efforts.
I didn't profile systematically. My test pages were extremely slow in production and one of the first things I tried was turning off TailwindMerge and that fixed it. Thankfully, memoizing it made it fast again.
I am using a module to namespace and the use this method definition in the module and call it directly. My only worry is thread safety. I will need to investigate that later.
def self.tailwind_merger
@tw_merger ||= TailwindMerge::Merger.new
end
I'm going to close this unless someone else shows me performance comparisons.
I am also building a Rails UI Kit, also a port of shadcn. It started quite some time back and your library is providing motivation to complete it :) I have a very different approach from yours but I also use Tailwind merge.
When I used it like you did
it had a negative impact on production performance. I had to memoize it to get good performance. Also, the performance optimizations of the gem - https://github.com/gjtorikian/tailwind_merge#performance - kicks in only if you the same instance AFAIK.
It could be that, this is specific to my implementation. I haven't tested shadcdn-rails.