Robert Rohde wrote:
As I suggested yesterday, perhaps not very clearly, I think the
sensible thing to do is to bypass the Parser on most calls to messages
like "Welcome to {{SITENAME}}" by caching the post-transformed version
of the message, e.g "Welcome to Wikipedia", in the MessageCache
instead. This should be possible if the message has no context
dependent substitutions (e.g. if the message avoids things like
substitution variables and context dependent magic words like
{{NAMESPACE}}).
It would mean teaching the parser to look for context dependent
elements and having some way to communicate that to the MessageCache
to allow it to decide whether to cache the pre-transformed or
post-transformed version. It would also mean categorizing magic words
to identify whether caching is allowed, but that seems like a
straightforward extension of the TTL hinting already done in
MagicWord. The magic word caching hints could also be used to help
decide how long the post-transformed version is likely to be good for.
My (somewhat vague) idea of how this could be done would be to add a new
"constant-folding" mode to the parser which only does brace substitution
for magic words that it knows to be essentially constant (and whose
parameters, if any, can be folded down to something that contains no
braces, numbered message parameters nor anything else potentially
variable) and leaves everything else alone.
It's been quite some time since I last looked at the parser code in any
detail, but surely that can't be *that* hard -- after all, we already
have the "pre-save transform" which does something quite similar.
The localization cache can just run everything through the parser in
constant-folding mode, cache the output, and then use the current check
(which I think simply checks for the presence of "{{") to determine if
the message needs to be reparsed when it's actually used.
(Although Roan's suggestion of also folding things like {{CURRENTYEAR}}
and passing their expiration time to the cache may also be worth
considering. We could then just treat e.g. {{SITENAME}} as having an
infinite expiration time, and any truly uncacheable magic words as
expiring immediately.)
--
Ilmari Karonen