Performance Issue: CPU Load
-
I’m writing to report a performance issue I’ve traced in My Calendar that’s causing serious CPU load on a client site (WordPress on SiteGround, ~77 events, one weekly recurring event ending in 5 weeks).
Symptom: With the plugin active, the homepage (which uses [my_calendar_upcoming]) takes 30-40 seconds to load. Disabling the plugin drops load time to under 1 second. This was severe enough that SiteGround suspended the site for excessive CPU usage.
Using Query Monitor, I found that for every event rendered, the plugin runs a nearly identical stack of ~15-20 separate queries, including:
- mc_get_first_event()
- mc_get_categories()
- mc_get_category()
- mc_get_location()
- mc_get_location_post()
- mc_check_category_relationships()
- Two separate WP_Term_Query calls (mc-location-access and mc-event-access taxonomies)
- update_meta_cache() / delete_metadata() for _occurrence_overlap
- mc_ts(), which runs SELECT TIMEDIFF(NOW(), UTC_TIMESTAMP) fresh for every single event, even though this value is identical across all events in the same request
None of these individual queries are slow on their own (0.0001-0.0003s each), but the volume multiplies quickly – roughly 15-20 queries x 50+ events rendered = 750+ queries per page load. I’ve confirmed this isn’t a caching issue on my end: both Memcached (object cache) and SiteGround’s Dynamic Caching (full-page cache) are active, but since these are raw custom SQL queries against the My Calendar tables rather than calls wrapped in wp_cache_get()/wp_cache_set(), they bypass object caching entirely.
A few things that stood out as easy wins:
- mc_ts() / the TIMEDIFF(NOW(), UTC_TIMESTAMP) calculation could be computed once per request and reused, rather than recalculated per event.
- mc_get_categories(), mc_get_category(), and mc_get_location() all look like good candidates for wrapping in wp_cache_get()/wp_cache_set(), since the same categories and locations are being re-fetched repeatedly across events.
- The repeated WP_Term_Query calls for access-control taxonomies per event also seem like they could be batched rather than run individually.
For my part, I’ve disabled the plugin on the effected website. Hoping this is a helpful report so the fix can be included on the next update.
Thanks
Stacey
You must be logged in to reply to this topic.