bkiers / Liqp

An ANTLR based 'Liquid Template' parser and rendering engine.
MIT License
165 stars 94 forks source link

Fix performance issue w.r.t. not_out_end #311

Closed bkiers closed 3 weeks ago

bkiers commented 1 month ago

Fixes #310

I tested this by adding ./src/test/test.liquid with the contents from the issue #310 (https://github.com/user-attachments/files/17264247/test_template_string.txt)

public class PerfTest {

    @Test
    public void test() throws Exception {
        int repeat = 100;
        TemplateParser templateParser = new TemplateParser.Builder().build();
        long start = System.currentTimeMillis();

        for (int i = 0; i < repeat; i++) {
            templateParser.parse(new File("./src/test/test.liquid"));
        }

        System.out.printf("%d ms.", System.currentTimeMillis() - start);
    }
}

when not_out_end was:

not_out_end
 : ( ~OutEnd )+
 ;

the test ran in around 8000-8500 ms. With the changes in this PR the test ran in around 3000-3200 ms.

bkiers commented 1 month ago

~Last commit was wrong. Let me fix.~

OK, done.

msangel commented 4 weeks ago

I will publish these changes as new version