WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 2 years ago

#36953 closed defect (bug) (fixed)

Meta lazyloading can cause excessive calls to object cache

Reported by: boonebgorges Owned by: DBrumbaugh10Up
Milestone: 4.6 Priority: normal
Severity: normal Version:
Component: Query Keywords: good-first-bug needs-unit-tests has-patch
Focuses: performance Cc:

Description

WP_Query calls wp_queue_posts_for_term_meta_lazyload(), which in turn grabs the {$taxonomy}_relationships cache for each found post, for each taxonomy that they belong to. So if you're fetching 20 items, and each item is in 10 taxonomies, the process will require 200 cache gets. This is in addition to the dozens of other other cache priming gets that happens in WP_Query.

On very high traffic sites running an object cache backend, the high volume calls to the cache can cause performance issues.

A truly general fix would be wp_cache_get_multi(), which would allow functions like this to reduce cache roundtrips by one or two orders of magnitude. See #20875.

In the meantime, two things to explore:

  1. WP_Query decides whether to queue posts for termmeta lazyloading based on the value of 'update_term_meta_cache'. This should be more fine-grained. A new WP_Query parameter lazyload_term_meta, which would default to the value of update_term_meta, seems appropriate. This way, very high-traffic sites that don't use termmeta and thus don't need to lazyload it can disable the feature in a targeted way, via a pre_get_posts callback.
  2. Look for ways to cut back on cache queries in the lazyload process. Not sure if that's feasible, since different posts keep their taxonomy relationships in different cache buckets, but it's worth looking into.

1 should be doable for 4.6.

cc @patrickgarman, who brought this to my attention.

Attachments (1)

36593.diff (1.2 KB) - added by DBrumbaugh10Up 2 years ago.
Patch file for 36953

Download all attachments as: .zip

Change History (9)

#1 @boonebgorges
2 years ago

  • Keywords needs-patch good-first-bug needs-unit-tests added

#2 @lukecavanagh
2 years ago

Less cache gets would be a good thing.

#3 @lukecavanagh
2 years ago

So was term_meta_lazyload depreciated in WP 4.5?

@DBrumbaugh10Up
2 years ago

Patch file for 36953

#4 @DBrumbaugh10Up
2 years ago

  • Keywords has-patch added; needs-patch removed

@boonebgorges The patch implements option #1 that you've listed as far as I can understand. What I'm missing I guess is why a site can't just set update_term_meta_cache to "false" in the pre_get_posts call back?

Or did I miss your intent?

#5 @boonebgorges
2 years ago

So was term_meta_lazyload depreciated in WP 4.5?

No. Term meta lazyloading was introduced in 4.5.

@boonebgorges The patch implements option #1 that you've listed as far as I can understand

Thanks. I mistyped - I meant that the value of lazyload_term_meta should fall back on the value of update_term_meta_cache.

What I'm missing I guess is why a site can't just set update_term_meta_cache to "false" in the pre_get_posts call back?

This can already be done. But it makes it impossible to prime the term cache without priming the termmeta cache.

#6 @boonebgorges
2 years ago

In 37589:

Allow term meta lazy-loading to be selectively disabled in WP_Query.

The process of lazy-loading can be resource intensive for object that have
terms in large numbers of taxonomies and are running a persistent object cache.
This new parameter allows the feature to be disabled in these cases.

Props DBrumbaugh10Up.
See #36953.

#7 @DrewAPicture
2 years ago

  • Owner set to DBrumbaugh10Up
  • Status changed from new to assigned

Assigning to mark the good-first-bug as "claimed".

#8 @boonebgorges
2 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

Going to mark this as resolved for 4.6. We can explore further improvements (especially integration with cache multi-get - #20875) in future releases.

Note: See TracTickets for help on using tickets.