I'm excited to contribute to the tailwind-merge-php package. I've found an opportunity to optimize the caching logic, which should improve performance slightly. It cuts the number of cache calls in half.
What I discovered:
The current caching logic uses a two-step process: first checking if the key exists in the cache, then retrieving the value.
This approach results in unnecessary method calls when the key exists in the cache.
What I did to fix it:
Simplified the caching logic by directly attempting to retrieve the value from the cache.
If the retrieved value is not a string (including null for non-existent keys), we simply continue with the existing logic.
This change eliminates the need for a separate has() check, potentially improving performance.
Here's the exact change:
Before
if ($this->cache->has($key)) {
$cachedValue = $this->cache->get($key);
if (is_string($cachedValue)) {
return $cachedValue;
}
}
After
$cachedValue = $this->cache->get($key);
if (is_string($cachedValue)) {
return $cachedValue;
}
I hope this helps improve the package! Let me know if you'd like me to explain anything further or make any changes.
Hi there! 👋
I'm excited to contribute to the tailwind-merge-php package. I've found an opportunity to optimize the caching logic, which should improve performance slightly. It cuts the number of cache calls in half.
What I discovered:
What I did to fix it:
has()
check, potentially improving performance.Here's the exact change:
Before
After
I hope this helps improve the package! Let me know if you'd like me to explain anything further or make any changes.
Thanks for considering my contribution! 😊