Make WordPress Core

Opened 15 years ago

Closed 15 years ago

Last modified 14 years ago

#10971 closed defect (bug) (fixed)

Translate functions when no locale are expensive no-ops

Reported by: johanee's profile johanee Owned by: westi's profile westi
Milestone: 2.9 Priority: normal
Severity: major Version: 2.9
Component: Performance Keywords: has-patch
Focuses: Cc:

Description (last modified by westi)

When there is no locale loaded WordPress creates a new empty Translations object on every call to any translation function (__(), ...) which is then used to do the fruitless no-op lookup.

Reverting to the 2.7 style (of testing $l10n[$domain] directly in translate() and friends) makes page load of new install of 2.9 trunk front page 17% faster!!

Attachments (4)

l10n-translation-noop-performance.patch (2.9 KB) - added by johanee 15 years ago.
Make not translating text much, much faster
l10n-translation-empty-class.patch (1.2 KB) - added by johanee 15 years ago.
Use minimal Empty_Translation object when none available
l10n-translation-noop-performance-2.patch (2.8 KB) - added by johanee 15 years ago.
Non-object approach take 2
use-noop-translations.php (502 bytes) - added by nbachiyski 15 years ago.

Download all attachments as: .zip

Change History (15)

15 years ago

Make not translating text much, much faster

#1 @westi
15 years ago

Surely a much better solution to this is to store a static empty translations object and return that rather than re-introducing a lot of duplicated code.

#2 @westi
15 years ago

And by an empty translations object I mean one which just returns the strings passed to it not the base Translations class which does some extra work.

15 years ago

Use minimal Empty_Translation object when none available

#3 @johanee
15 years ago

Do you mean something like the attached? It is slightly less efficient of course -- the price of abstractions -- but still much better than the current version.

#4 @westi
15 years ago

Yes something like that is much more attractive.

It makes writing plugins that use the filter much simpler as they don't have to cater for both cases.

#5 @westi
15 years ago

  • Description modified (diff)
  • Owner set to westi
  • Status changed from new to accepted

#6 @johanee
15 years ago


Regarding the filters, though: if you mean the gettext[_with_domain] filters please note that the cases there were identical as far as consumers of the filter are concerned (in the original patch).

I'll attach an updated version of the original approach that makes this more clear, just to be sure. Please select whichever approach you prefer.

If you want any modifications to any of the approaches or have any further questions please just say so.

15 years ago

Non-object approach take 2

#7 @johanee
15 years ago

Performance for the various patches:

Average total page load time (ab -c 1 -n 100
Clean 2.9.0 revision 12065 install

1 post front page
org: 47ms
empty-class: 42ms
noop-performance-2: 41ms

10 post front page
org: 95ms
empty-class: 87ms
noop-performance-2: 84ms

Numbers are stable.

#8 @nbachiyski
15 years ago

I like westi's idea. A lot cleaner code, than repeating the logic in each function.

I added the NOOP_Translation class to GlotPress:

Keeping the instance if the empty translation class in the global object is both cleaner and faster. No static variables this way. Patch attached.

#9 @westi
15 years ago

Thanks nikolay.

I'll merge the whole of the updated pomo and then apply that patch.

#10 @westi
15 years ago

(In [12079]) Merge updated pomo code. Includes new NOOP_Translations class see #10971 props nbachiyski.

#11 @westi
15 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

(In [12080]) Switch to using NOOP_Translations for untranslated sites. Fixes #10971 props nbachiyski.

Note: See TracTickets for help on using tickets.