Skip to content

Smarty 5.5.1 significantly slower than 4.5.5 #1134

@screenflavor

Description

@screenflavor

Hi wisskid, hi smarty community,
we are about to update our smarty version from 4.5.5 to 5.5.1. We wrote some unit tests and realized that the new version runs significantly slower than the old version.
For example the following code needs 3.134 s with v4.5.5 and 3.976 s with v5.5.1:

    for ($i = 0; $i < 200000; ++$i) {
        $smartyTemplate = 'string:{assign var=title value="some title"}
            {$title|lower}';
        $result = $this->fixture->fetch($smartyTemplate);
        $this->assertEquals('some title', trim($result));
    }

I also tried it out with a registered php function:

    for ($i = 0; $i < 200000; ++$i) {
        $smartyTemplate = 'string:{assign var=title value="some title"}
            {$title|urlencode}';
        $result = $this->fixture->fetch($smartyTemplate);
        $this->assertEquals('some+title', trim($result));
    }

I could increase the speed and get it close to version 4 by calling the generated template function directly like:

/**
 * @throws \Smarty\Exception
 */
public function testUrlEncode(): void
{
    for ($i = 0; $i < 100000; ++$i) {
        $smartyTemplate = 'string:{assign var=title value="some title"}
            {$title|urlencode}';
        $template = $this->fixture->createTemplate($smartyTemplate);
        ob_start();
        $this->content_68433e5d15ee35_72556349($template);
        ob_end_clean();
        $result = ob_get_clean();
        $this->assertEquals('some+title', trim($result));
    }
}

function content_68433e5d15ee35_72556349 (\Smarty\Template $_smarty_tpl)
{
    $_smarty_current_dir = '.';
    $_smarty_tpl->assign('title', "some title", false, NULL);
    echo $_smarty_tpl->getSmarty()->getModifierCallback('urlencode')($_smarty_tpl->getValue('title'));
}

We also did bigger tests with a template which included more than 100 registered php functions running in a 100000x loop. This resulted in 3.368 s vs 10.748 s. But I think the easier template above already shows the difference sufficently.

To me it looks like there is a bigger performance overhead in the smarty 5 classes.
Did you do some performance tests during development of the new major version? Can you confirm that smarty 5 is significantly slower? Are there some options or tricks to bring the performance close to verson 4?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions