Make WordPress Core

Opened 7 years ago

Closed 8 weeks ago

#43096 closed enhancement (wontfix)

Reduce redundant calls to translate()

Reported by: superdav42's profile superdav42 Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: I18N Keywords: has-patch needs-refresh close
Focuses: performance Cc:

Description

Profiling the default WordPress install I noticed translate functions where being called 1700+ times and many times with duplicate strings. This patch uses static vars in a few key places to avoid translating the same string multiple times. Gives about a 14% reduction in page response time and a very slight memory increase. See https://blackfire.io/profiles/compare/6b2513f0-de36-400d-9e39-2349644b3d57/graph

Attachments (1)

43096.diff (20.5 KB) - added by superdav42 7 years ago.
patch

Download all attachments as: .zip

Change History (8)

@superdav42
7 years ago

patch

#2 @pento
6 years ago

  • Version trunk deleted

#3 @swissspidy
17 months ago

  • Keywords has-patch needs-refresh close added

At least for the WP_Locale class this has already been implemented in the meantime.
For the other cases I am not particularly fond of using static variables for caching. That just makes testing and debugging a bit harder and decreases readability.

#4 @SergeyBiryukov
17 months ago

Hi there, thanks for the ticket! Sorry it took so long for someone to get back to you.

As noted above, for WP_Locale this was addressed in [52956] / #54564. Other changes make sense too at a glance, but they make things less flexible for switching between locales during the request, unit testing, and might lead to an issue where post type or taxonomy labels cannot be retrieved in the correct locale after the initial call, so maybe we should look at other ways to optimize translations instead.

Last edited 17 months ago by SergeyBiryukov (previous) (diff)

#5 @pbearne
3 months ago

With the changes to PHP translation files, do we still need to do this?

#6 @swissspidy
3 months ago

That's a good point. It's certainly less of a bottleneck right now, although it's always great being able to reduce unnecessary function calls. However, the above concerns with the approach are still valid. For example, static variables would break locale switching and tickets such as #38643.

A new performance analysis here would be helpful to see whether there is still room for optimization or not.

#7 @pbearne
8 weeks ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

The code has been refactored, so this patch is not needed

Note: See TracTickets for help on using tickets.