baryshev / template-benchmark

111 stars 49 forks source link

Swig tuning, autoescape: false #4

Closed atma closed 11 years ago

atma commented 11 years ago

Swig has a strange behaviour with autoescape. it is highly recommended to leave this on in production but when it switched off and escaping forced via the escape filter swig has an incredible results.

ECT Escaped : 1579ms Unescaped : 78ms Total : 1657ms

Dust Escaped : 1831ms Unescaped : 250ms Total : 2081ms

Hogan.js Escaped : 2128ms Unescaped : 510ms Total : 2638ms

Fest Escaped : 2914ms Unescaped : 160ms Total : 3074ms

Handlebars.js Escaped : 2999ms Unescaped : 176ms Total : 3175ms

EJS without with Escaped : 3333ms Unescaped : 269ms Total : 3602ms

doT Escaped : 3553ms Unescaped : 45ms Total : 3598ms

Swig Escaped : 259ms Unescaped : 260ms Total : 519ms

Eco Escaped : 5784ms Unescaped : 487ms Total : 6271ms

EJS Escaped : 4353ms Unescaped : 1848ms Total : 6201ms

Jade without with Escaped : 5883ms Unescaped : 2110ms Total : 7993ms

CoffeeKup Escaped : 2774ms Unescaped : 5990ms Total : 8764ms

Jade Escaped : 10747ms Unescaped : 7282ms Total : 18029ms

baryshev commented 11 years ago

Escape filter does not actually escape data with autoescape switched to false in my tests

atma commented 11 years ago

In my test for swig I just manually do escape with swig escape filter when necessary and data was escaped. E.g. {{ var|e }} Thanks, I'll review this.

baryshev commented 11 years ago

I tryed to use {{ var|e }} like in your PR, but data still unescaped. console.log(html) in benchmark.js at line 24.

atma commented 11 years ago

You are right. Swig has two different types of escaping: html & js, by default the first. But when no type given escaping doesn't work. WIth {{ var|e('html') }} it works as expected. Anyway swig now ~30% faster

Escaped : 3598ms Unescaped : 260ms Total : 3858ms

baryshev commented 11 years ago

I see no difference between autoescape : true and e('html') filter on my environment.

With e('html') filter:

Swig Escaped : 5052ms Unescaped : 370ms Total : 5422ms

With autoescape : true:

Swig Escaped : 5023ms Unescaped : 359ms Total : 5382ms

atma commented 11 years ago

It's strange, I have the same (~30 better) results on a few environments. But nevermind, this horrible escaping style not for production. Thanks for good point, just I'm using swig in one of my projects.