#10971 closed defect (bug) (fixed)
Translate functions when no locale are expensive no-ops
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 )
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)
Change History (15)
#1
@
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
@
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.
#3
@
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
@
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
@
15 years ago
- Description modified (diff)
- Owner set to westi
- Status changed from new to accepted
#6
@
15 years ago
Good.
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.
#7
@
15 years ago
Performance for the various patches:
Average total page load time (ab -c 1 -n 100 http://example.org) 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
@
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: http://trac.glotpress.org/changeset/291
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
@
15 years ago
Thanks nikolay.
I'll merge the whole of the updated pomo and then apply that patch.
Make not translating text much, much faster