Make WordPress Core

Opened 6 years ago

Last modified 5 years ago

#10971 closed defect (bug)

Translate functions when no locale are expensive no-ops — at Version 5

Reported by: johanee Owned by: 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!!

Change History (7)

6 years ago

Make not translating text much, much faster

#1 @westi
6 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
6 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.

6 years ago

Use minimal Empty_Translation object when none available

#3 @johanee
6 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
6 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
6 years ago

  • Description modified (diff)
  • Owner set to westi
  • Status changed from new to accepted
Note: See TracTickets for help on using tickets.