Performance Degradation from wc_var_prices Transient Calculation for Variable Products
Summary:
The bug report describes a significant performance issue on WooCommerce category and product pages, where page load times intermittently spike to 8-9 seconds. This slowdown is directly traced to the calculation and building of the wc_var_prices transient for variable products.
The problem is particularly severe for products with a large number of variations, with one cited example having 792 variations. The initial page load that triggers the transient creation is slow, but subsequent loads are fast (around 1.5 seconds) until the transient is cleared again. This suggests the core issue is the computational cost of generating the transient data for complex products.
A potential code-level inefficiency was identified as a contributing factor. The get_variation_prices() method is called twice during the process—once with $for_display = false (from is_on_sale()) and once with $for_display = true (from get_price_html()). Even when the final prices are identical for both contexts, this results in duplicate calculations and the generation of two separate price hashes, unnecessarily increasing the processing time.
How to Replicate:
- Create or import variable products with a high number of variations (e.g., 36 and 792).
- Ensure the
wc_var_pricestransient for these products is not present (e.g., by clearing all transients). - Navigate to a category archive page or product page that contains these variable products.
- Observe the page load time. The initial load will be very slow (e.g., 8-9 seconds) as the transient is built.
- Reload the page. The load time will be significantly faster (e.g., 1.5 seconds) as it now uses the cached transient.