#10971 closed defect (bug) (fixed)
Translate functions when no locale are expensive no-ops
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 2.9 |
| Component: | Performance | Version: | 2.9 |
| Severity: | major | Keywords: | has-patch |
| 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)
Change History (15)
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.
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.
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.
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.
- Description modified (diff)
- Owner set to westi
- Status changed from new to accepted
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.
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.
comment:8
nbachiyski — 4 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.
nbachiyski — 4 years ago
Thanks nikolay.
I'll merge the whole of the updated pomo and then apply that patch.
comment:10
westi — 4 years ago
comment:11
westi — 4 years ago
- Resolution set to fixed
- Status changed from accepted to closed

Make not translating text much, much faster