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)

@johanee6 years ago

Make not translating text much, much faster

comment:1 @westi6 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.

comment:2 @westi6 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.

@johanee6 years ago

Use minimal Empty_Translation object when none available

comment:3 @johanee6 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.

comment:4 @westi6 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.

comment:5 @westi6 years ago

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