{"issue":{"state":"open","created_at":"2011-12-01T19:52:06Z","updated_at":"2011-12-02T06:30:10Z","comments":2,"user":{"gravatar_id":"f309acddadf2a552d3d7a402a80081e5","id":1228301,"url":"https://api.github.com/users/VladimirTechMan","avatar_url":"https://secure.gravatar.com/avatar/f309acddadf2a552d3d7a402a80081e5?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"VladimirTechMan"},"body":"It is quite common, for a good fraction of the templates in use, to contain simple sequences of adjacent blocks of text (most often, some HTML code) and expression result printouts. When compiling those templates, Twig translates those original sequences directly into sequences of 'echo' statements where each text block or expression result is printed out with a separate 'echo' statement.\r\n\r\nAt the same time, PHP allows the embedded language construct of 'echo' to have multiple \"arguments\" separated by commas (not \"dots\"). In that case all the arguments (PHP expressions) get evaluated and printed out in the sequence given. Compared to printing the same chain of values by separate 'echos' (one per value), a multi-value 'echo' is executed a little bit faster by PHP -- the more values are \"bundled\" into a single 'echo', the quicker.\r\n\r\nIf a multi-value echo is executed just on rare occasions, the resulting speedup is hardly noticeable (thus unimportant). But it starts paying off when calling the same code for hundreds and thousands page requests per sec, which is where Twig tries to be (and is) one of the best template frameworks in its class.\r\n\r\nWith all that in mind, I would like proposing a few code changes -- quite simple and moderate in size -- to allow combining adjacent printouts of text blocks and expressions into multi-value echoes in the templates compiled by Twig. The related handling is controlled with a new Environment parameter called \"multivalue_echoes\" that takes a boolean value so that the effect can always be controlled by the Twig users.\r\n\r\nInternally the change is implemented with two extra node types (classes) added, Twig_Node_PrintMultiple and Twig_Node_SandboxedPrintMultiple. The appropriate changes have been done in Twig_Environment, Twig_Parser, and Twig_NodeVisitor_Sandbox. See the deltas for details.\r\n\r\nThe changes are fully compatible with the optimizations done by Twig, including the newly added OPTIMIZE_VAR_ACCESS.\r\n\r\nI would like to welcome Fabien as well as other Twig developers and users to look at this proposal, assess it themselves (the code changes done and the results) and (hopefully) consider making it a part of a future release of Twig.\r\n\r\nIf this proposed addition to Twig will eventually be of interest and of help to others, I will be glad.","assignee":null,"id":2418933,"pull_request":{"patch_url":"https://github.com/fabpot/Twig/pull/543.patch","html_url":"https://github.com/fabpot/Twig/pull/543","diff_url":"https://github.com/fabpot/Twig/pull/543.diff"},"labels":[],"number":543,"title":"Allow using multi-value echoes for adjacent text and expression result printouts in compiled templates","closed_at":null,"html_url":"https://github.com/fabpot/Twig/issues/543","url":"https://api.github.com/repos/fabpot/Twig/issues/543","milestone":null},"action":"created","comment":{"created_at":"2011-12-02T06:30:10Z","updated_at":"2011-12-02T06:30:10Z","user":{"gravatar_id":"f1a2c5905e121d09feba5ad73898ffca","id":47313,"url":"https://api.github.com/users/fabpot","avatar_url":"https://secure.gravatar.com/avatar/f1a2c5905e121d09feba5ad73898ffca?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"fabpot"},"body":"I have already benchmarked this and the speed improvement was never worth it, even with many echo statements.","id":2986865,"url":"https://api.github.com/repos/fabpot/Twig/issues/comments/2986865"}}