Speed up template rendering

Significant speed-up to the template rendering in  Kernel::Output:HTML::Layout->Output. Please read the commit message for more details.