Performance

Diagnose high memory usage traced to a specific plugin

A scenario prompt for tracking a WooCommerce fatal "allowed memory size exhausted" error to a related-products plugin, weighing a code fix against just raising the memory limit at the hosting level.

Works with Claude / GPT175 uses 4

The prompt

performance-high-memory-usage-plugin
A WooCommerce store is throwing "Allowed memory size of 268435456 bytes exhausted"
fatal errors, specifically during bulk product imports and occasionally on category
pages with a lot of products. PHP memory_limit is already set to 256M.

HOSTING: [SiteGround GrowBig plan, memory_limit adjustable via wp-config but capped by
the hosting plan's overall PHP limit]
QUERY MONITOR / DEBUG LOG NOTES: [a related-products recommendation plugin is loading
every product in a given category into memory at once to compute recommendations,
rather than paginating or using a cached lookup table]

Work through this as a consultant tracing a memory leak, not just recommending a bigger
limit:
1. Confirm the plugin as the likely root cause given the debug notes, and explain why
   "load everything into memory to compute recommendations" is a red flag pattern
   versus a paginated query or a precomputed lookup table refreshed on a schedule.
2. Give the code-level fix if this is a custom or lightly-coded plugin: batching the
   product loop, using WP_Query with fields=>'ids' instead of full post objects, or
   caching the computed recommendation set as a transient instead of recalculating it
   on every page load.
3. If it's a closed-source commercial plugin where the code can't be touched, give the
   fallback: a setting to limit how many products it considers, or disabling the
   feature during bulk imports specifically and re-enabling after.
4. Address raising memory_limit itself: explain this treats the symptom, not the
   cause, and that SiteGround's GrowBig plan may cap the effective ceiling regardless
   of what wp-config requests, meaning this specific fix might need a hosting-plan
   upgrade, not just a config edit.
5. Flag the edge case: if this plugin's recommendations feed into a separate email
   marketing automation, disabling it during imports to stop the crashes could
   silently break that integration too, so check what else depends on it before
   turning it off.

Raising memory_limit is the fix everyone reaches for first because it’s a one-line change, but it just delays the same crash until the next larger import. This prompt pushes past that to find what’s actually allocating memory unboundedly, and it treats “disable the plugin during imports” as a real option only after checking what else depends on it.

Paste your own PHP error log line and Query Monitor’s memory-usage-by-plugin panel if you have one, that panel usually points at the culprit in seconds.