WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 13 months ago

#32052 new enhancement

Add out of the box support for MO file caching

Reported by: nicofuma Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 4.2
Component: I18N Keywords: needs-patch
Focuses: performance Cc:

Description (last modified by SergeyBiryukov)

While profiling WordPress with Blackfire we found that parsing an mo file is a heavy task, and it's done on each page.

Parsing of a .mo file

We propose to use the Object Cache API to not re-parse the file if it hasn't changed.
This way any non English installations with a plugin implementing the Object Cache API could benefit of a significant performance improvement.

You can see here a comparison showing the performance improvement:
comparison with the proposed patch

We found that a few plugins are doing the same thing but they are not used very much and we think it could be great to have it mainstream.

Attachments (5)

04222015-1020_mo_caching.diff (1.1 KB) - added by nicofuma 3 years ago.
proposal
default-mo.png (18.8 KB) - added by nicofuma 3 years ago.
Parsing of a .mo file
mo-cache-comp.png (19.4 KB) - added by nicofuma 3 years ago.
comparison with the proposed patch
04222015-1119_mo_caching.diff (1.3 KB) - added by nicofuma 3 years ago.
Updated patch to avoid any notice
04222015-1551_mo_caching.diff (829 bytes) - added by nicofuma 3 years ago.
patch moved to load_textdomain()

Download all attachments as: .zip

Change History (23)

@nicofuma
3 years ago

proposal

@nicofuma
3 years ago

Parsing of a .mo file

@nicofuma
3 years ago

comparison with the proposed patch

#2 @nicofuma
3 years ago

I just noticed a small typo in the description, I forgot a 'not' in the last sentence:

We found that a few plugins are doing the same thing but they are not used very much and we think it could be great to have it mainstream.

#3 @SergeyBiryukov
3 years ago

  • Description modified (diff)

@nicofuma
3 years ago

Updated patch to avoid any notice

#4 @nicofuma
3 years ago

Just to be a little more precise, these 40ms represent about 30% of the wall time.

Sergey: thanks for the description

Update: We published a blog post about this issue.

Last edited 3 years ago by nicofuma (previous) (diff)

#5 @Rarst
3 years ago

Discussion point — should it be only object cache or should it just use Transients API? Would caching this kind/amount of data in database with transient be beneficial in absence of object cache in installation?

#6 @ocean90
3 years ago

Hello nicofuma,

thanks for your report and the patch.
The PO/MO libraries are used in multiple projects and shouldn't have any WordPress dependencies. So the right place for this is probably load_textdomain().
It's also worth to mention that only a small group of users will benefit of this, since there is no persistent object cache per default.

@nicofuma
3 years ago

patch moved to load_textdomain()

#7 @nicofuma
3 years ago

I missed that the PO/MO libraries shouldn't have any WordPress dependencies, sorry.

Here is a new version of the patch moved to load_textdomain().
I also moved from the Object Cache API to the Transient API and here are the profiles:

Current state: profile
Without any Object Cache: profile comparison with current
With W3 enabled (and its disk Object Cache strategy): profile comparison with current

To sump-up: caching this kind/amount of data in database is beneficial (from 47ms to 25ms). Enabling the Object Cache makes things even faster (from 47ms to 8ms).
Thanks to the transient API we use automatically the best caching strategy (db versus object cache).

Last edited 3 years ago by nicofuma (previous) (diff)

#8 @nicofuma
3 years ago

  • Keywords has-patch added

#9 @nicofuma
3 years ago

Hi,

Just wanted to know if the last patch is good enough or if something else should be changed.

#10 @dd32
3 years ago

Personally I'm a little wary of storing the parsed MO files into transients, as pointed out, that means most users will get the data shifted to the Database instead (So it trades CPU+Disk for Memory+network bandwidth - MySQL & Object Caches are often not on the same machine)

It also means that the memory usage of PHP related to the strings will double (as it'll be stored within the object cache global, as well as in the MO reader), that doesn't seem like much, but it quickly adds up in a localised install.

There's a few people interested in the performance of localised installs (myself included), so you can be sure that your patch will be reviewed, but sometimes it can take a bit of time while all the options are weighed up.

#11 @nicofuma
3 years ago

I perfectly understand it can take time. It's just that if there is some concerns (or other options) I'll be happy to discuss about them :)

In my language (in french) it represents around 1.6MB in the database (without compression) and 2.5MB in PHP. It's not that much but it's not negligible either. That's why I initially proposed to use the Object Cache API instead of the transient but the performance improvement is still noticeable when it is stored in the database.

Note: I just saw that the links in the description are wrong. If someone want to see the hole data:

This ticket was mentioned in Slack in #core-i18n by ocean90. View the logs.


19 months ago

#14 @swissspidy
19 months ago

  • Keywords needs-patch added; has-patch removed

Transients aren't really the solution to this. What about just using wp_cache_get() / wp_cache_set() and therefore leveraging an external object cache if configured?

Also, it's likely that Ginger-MO will already improve performance quite a bit.

#15 @PerS
19 months ago

@swissspidy, I agree and suggest this is merged with #34114

Last edited 18 months ago by ocean90 (previous) (diff)

This ticket was mentioned in Slack in #core-i18n by ocean90. View the logs.


18 months ago

#17 @ocean90
18 months ago

  • Milestone changed from Awaiting Review to Future Release

This ticket was mentioned in Slack in #core-i18n by soderlind. View the logs.


13 months ago

Note: See TracTickets for help on using tickets.