Make WordPress Core

Opened 15 months ago

Last modified 9 months ago

#58001 new enhancement

Lazy load user capabilities in WP_User object

Reported by: spacedmonkey's profile spacedmonkey Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Users Keywords: has-patch has-unit-tests
Focuses: multisite, performance Cc:

Description

WP_User object are used throughout WordPress and are loaded on the front end in WP_Query. This means creating a WP_User object and this calls for_site method. This calls to user meta and setups capability data. For a page with multiple users on it, this setup of users, can be done multiple times. Loading user meta for all the users, can be a problem, as this can be a lot of rows of data. For example, this can result in 150 rows being loaded from the database for just 10 users. For multisites or sites that have plugins that are heavy users of user meta, that number can get much higher.

User meta is only loaded along with users, as it is needed for capability data. To improve performance, find someway to lazy load the capability only when they are used and also lazily load user meta at the same time.

Change History (4)

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


10 months ago
#1

  • Keywords has-patch has-unit-tests added

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


10 months ago

#3 @prettyboymp
9 months ago

#59430 was marked as a duplicate.

#4 @prettyboymp
9 months ago

Similar ticket in #59430 - improve the loading performance of usermeta on network sites. Though the performance issue is somewhat different, it would be great if the solution we found solved both problems.

Core functionality like user roles and capabilities will likely need some extra special handling like what PR#5098 does. However, I still believe we need an API for:

  • Segmenting usermeta by blog to avoid autoloading user meta from other blogs on the network.
  • Allowing some usermeta to designated as non-autoload for data the requires rare usage and/or takes up too much memory to warrant loading/caching with the rest of the usermeta.
Note: See TracTickets for help on using tickets.