Make WordPress Core

Opened 4 weeks ago

Closed 5 days ago

#61624 closed enhancement (worksforme)

Cache translations

Reported by: leonardola's profile leonardola Owned by:
Milestone: Priority: normal
Severity: normal Version: 6.6
Component: I18N Keywords: reporter-feedback needs-patch close
Focuses: performance Cc:

Description

While working on a big codebase I found out that translations were taking up to 40% of request times.

When I dug deeper I noticed that some plugins were translating the same strings over and over and that WordPress does not cache the translations and ends up calling all of the gettext filters again each time.

It would be good to either cache the translations in WPCore or to at least add a hook that would allow plugins to cache translations and preemptive return a cached translation when they see fit instead of running all of the gettext filters again.

Change History (6)

This ticket was mentioned in PR #7010 on WordPress/wordpress-develop by leonardola.


4 weeks ago
#1

  • Keywords has-patch added

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

This PR adds a cache to the translate function to prevent gettext filters from running when the same string is being translated over and over by a plugin.

#2 @swissspidy
4 weeks ago

  • Keywords reporter-feedback needs-patch added; has-patch removed

Hi there and welcome to WordPress Trac!

Did you do any concrete profiling for this? I would love to see your data.

The new translation system in 6.5+ is actually very lean and translating the same string multiple times doesn't cause any additional overhead (O(1) to access it from an array).
What definitely can add overhead is applying all these filters every time. However, plugins rely on these, and suddenly not running the filters could be a backward compatibility break.

Also, as you will have seen on GitHub, your PR breaks a lot of existing tests, so it's definitely not as straightforward as adding a simple caching variable. Not to mention that calling determine_locale() so often in a hot code path actually makes things slower.

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


3 weeks ago

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


5 days ago

#5 @adamsilverstein
5 days ago

  • Keywords close added

This can probably be closed as worksforme - the reporter can always re-open if something was overlooked.

Last edited 5 days ago by adamsilverstein (previous) (diff)

#6 @swissspidy
5 days ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.