Optimize configurable-product page that varyies on heavy super attributes
The issue with Magento2’s module swatch
When you open the product page of a configurable product, Magento will load the configurable itself, but also its variants and the attributes it varies on.
Most of the time, you won’t notice any performance impact as your super attributes holds maybe tens of values.
But when it holds thousands, or ten of thousands of values, it may cost a few seconds (and a few memory) to gather these values.
When loaded, Magento will then build a new array with the identifiers of the values the product really needs.
In my case, my super attribute contained more than 15,000 values, so I had to make something to fix that.
Let change that silly behaviour
Here’s my plugin around \Magento\Swatches\Helper\Data::getSwatchAttributesAsArray, which completely replaces the default implementation.
I strongly recommend you to have a look to the original implementation, and to it caller,
\Magento\Swatches\Block\Product\Renderer\Configurable::getJsonSwatchConfig, to understand what it does.