Make WordPress Core

Opened 4 months ago

Last modified 5 weeks ago

#63021 assigned enhancement

Lazy load user meta

Reported by: spacedmonkey's profile spacedmonkey Owned by: flixos90's profile flixos90
Milestone: 6.9 Priority: normal
Severity: normal Version: 4.4
Component: Users Keywords: has-patch has-unit-tests
Focuses: performance Cc:

Description

Break out ticket from #58001.

WordPress already supports lazy loading for blog, comment, and term meta, significantly improving performance by reducing unnecessary database queries. However, user meta is still loaded immediately, which can lead to inefficiencies, especially on sites with large user bases or extensive user meta data.

Proposal:

This ticket proposes introducing a new wp_lazyload_user_meta() function to facilitate lazy loading of user meta. This function will be used within:

  • cache_users() to defer loading user meta until it’s explicitly requested.
  • The WP_User_Query class to optimise user queries and prevent unnecessary meta data retrieval.

Benefits:

  • Reduces the number of unnecessary database queries.
  • Improves performance, particularly for sites with many users.
  • Aligns user meta handling with existing lazy-loaded metadata (blogs, comments, terms).
  • Enhances consistency and efficiency across WordPress meta data handling.

Implementation Considerations:

  • wp_lazyload_user_meta( array $user_ids ) will preload user meta into cache but defer its retrieval until explicitly accessed.
  • Ensure backward compatibility by preserving expected behaviour for get_user_meta().
  • Modify cache_users() and WP_User_Query to use wp_lazyload_user_meta() instead of immediately fetching meta.
  • Evaluate and address potential edge cases, such as bulk user queries and caching mechanisms.

Follow on from #58185 #57801, #57496 #57645

Change History (7)

This ticket was mentioned in PR #8411 on WordPress/wordpress-develop by @spacedmonkey.


4 months ago
#1

  • Keywords has-patch has-unit-tests added

Introduce the wp_lazyload_user_meta function to queue user metadata for lazy-loading, optimizing user meta retrieval. Update related functions, tests, and metadata lazyloader to support this functionality, ensuring improved performance and consistency.

Trac ticket: https://core.trac.wordpress.org/ticket/63021

This ticket was mentioned in Slack in #core-performance by spacedmonkey. View the logs.


4 months ago

This ticket was mentioned in Slack in #core-performance by flixos90. View the logs.


4 months ago

#4 @spacedmonkey
4 months ago

  • Milestone changed from Awaiting Review to 6.8
  • Owner set to flixos90
  • Status changed from new to assigned

Assigning to @flixos90 for review.

#5 @flixos90
4 months ago

  • Milestone changed from 6.8 to 6.9

Similar to the related #58001, this needs to be punted to the 6.9 milestone. I don't think it requires early though as there are fewer risks with this change.

This ticket was mentioned in Slack in #core-performance by spacedmonkey. View the logs.


2 months ago

This ticket was mentioned in Slack in #core-performance by spacedmonkey. View the logs.


5 weeks ago

Note: See TracTickets for help on using tickets.