WC Filter Products by Attribute internal server error allowed memory bytes exhausted

WooCommerce Filter Products by Attribute widget was causing the shop page to produce an Internal Server Error 500 and preventing the page from displaying. While logged in and WP_DEBUG enabled the page loaded partially but failed when it was time to render the widget. Looking at WooCommerce -> Status -> Logs -> fatal-errors-*.log the error messages showed:

CRITICAL Allowed memory size of 422633582 bytes exhausted (tried to allocate 45768225 bytes) in .../wp-includes/wp-db.php on line 1260
CRITICAL Allowed memory size of 442553162 bytes exhausted (tried to allocate 12886364 bytes) in .../wp-includes/functions.php on line 617
Solution

For me the issue was solved by going to WooCommerce -> Status -> Tools and running the Term counts -> Recount terms and Regenerate the product attributes lookup table tools. You can also try to Regenerate product lookup tables and Clear WooCommerce transients.

If the issue keeps reoccurring at the point of rendering for the layered nav widget caching can be disable for it using a filter:

PHP
add_filter('woocommerce_layered_nav_count_maybe_cache', '__return_false');