Robert Rohde wrote:
A long while ago I remember looking at the parser and realizing that the recursive template expansion and argument handling led the parser to run all branches of #if and #switch statements before deciding which one to include.
In other words, given {{#if: something | statements_A | statements_B }}, the parser was fully expanding both statements_A and statements_B before checking #if to decide which one to keep. Obviously that is inefficient and in the case of very complicated conditional templates potentially very expensive.
The parser has changed so much since I last worked with it that I am having difficulty figuring out if this is still true. Hopefully, someone already went through and improved the branch handling logic, but if not, I would suggest that this would also be a good generalized target for improving template operation.
No it's not still true, yes dead branches are now eliminated. This was done at a significant cost to code complexity and there was quite a lot of overhead. The elimination of dead branches is the only reason the new parser has comparable performance to the old parser, otherwise it would have been slower.
-- Tim Starling