Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

version 3 is slower than version 2 #973

Closed
elover opened this issue Mar 7, 2015 · 8 comments
Closed

version 3 is slower than version 2 #973

elover opened this issue Mar 7, 2015 · 8 comments
Labels
Milestone

Comments

@elover
Copy link

elover commented Mar 7, 2015

version 2
image

@elover
Copy link
Author

elover commented Mar 7, 2015

version 3
image

@mmun
Copy link
Contributor

mmun commented Mar 7, 2015

Why are you including Handlebars.compile() in the benchmark?

@elover
Copy link
Author

elover commented Mar 7, 2015

this is my all code,you can try it in the chrome console with different version

var tem = "{{#each data}} <span>{{this}}</span> {{/each}}";
var i = 1000000;
var data = {
    data: []
};
while (i > 0) {
    data.data.push(i);
    i--;
}
var startTime = (new Date()).getTime();
console.log('start: ' + startTime);
var template = Handlebars.compile(tem);
var result = template(data);
var endTime = (new Date()).getTime();
console.log('end: ' + endTime);
console.log('total cost: ' + (endTime - startTime));

@elover elover closed this as completed Mar 7, 2015
@elover elover reopened this Mar 7, 2015
@mmun
Copy link
Contributor

mmun commented Mar 7, 2015

You should just compile the template once up front. Handlebars is primarily focused with runtime performance of the compiled template, not with fast compilation.

@kpdecker
Copy link
Collaborator

Seeing some regressions in the nightly tests:

v3

Execution Throughput
ops/msec            handlebars          compat              dust                eco                 mustache            WINNER(S)
---------------------------------------------------------------------------------------------------------------------------------
arguments           131 ±3 (5)          132 ±1 (5)          NA                  NA                  NA                  
array-each          225 ±3 (6)          145 ±2 (6)          338 ±4 (8)          130 ±7 (3)          100 ±2 (5)          
array-mustache      206 ±5 (9)          142 ±2 (7)          NA                  NA                  NA                  
complex             123 ±2 (4)          69 ±2 (4)           108 ±3 (6)          83 ±5 (4)           53 ±2 (2)           
data                107 ±2 (5)          83 ±2 (5)           NA                  NA                  NA                  
depth-1             128 ±3 (3)          127 ±3 (4)          NA                  117 ±6 (4)          79 ±2 (5)           
depth-2             56 ±1 (4)           53 ±1 (5)           NA                  56 ±3 (4)           30 ±1 (4)           
object-mustache     621 ±12 (5)         332 ±4 (5)          NA                  NA                  NA                  
object              520 ±13 (4)         298 ±6 (4)          258 ±5 (3)          153 ±9 (3)          168 ±6 (7)          
partial-recursion   126 ±4 (4)          92 ±3 (5)           16 ±1 (3)           NA                  95 ±3 (5)           
partial             122 ±3 (4)          93 ±2 (4)           109 ±3 (6)          NA                  61 ±1 (3)           
paths               701 ±15 (5)         501 ±12 (5)         197 ±8 (6)          161 ±9 (4)          91 ±2 (3)           
string              5698 ±176 (9)       5283 ±69 (7)        1072 ±13 (3)        434 ±31 (3)         1759 ±8 (5)         
subexpression       95 ±1 (5)           91 ±2 (5)           NA                  221 ±13 (4)         NA                  
variables           722 ±13 (4)         661 ±9 (4)          301 ±4 (7)          152 ±9 (3)          212 ±6 (5)          

v2:

Execution Throughput
ops/msec            handlebars          compat              dust                eco                 mustache            WINNER(S)
---------------------------------------------------------------------------------------------------------------------------------
arguments           119 ±4 (7)          117 ±1 (5)          NA                  NA                  NA                  
array-each          567 ±4 (4)          291 ±3 (6)          418 ±4 (7)          122 ±6 (3)          102 ±1 (5)          
array-mustache      581 ±4 (7)          272 ±2 (5)          NA                  NA                  NA                  
complex             275 ±1 (5)          100 ±1 (5)          179 ±5 (5)          84 ±5 (4)           58 ±1 (3)           
data                204 ±2 (4)          146 ±3 (4)          NA                  NA                  NA                  
depth-1             270 ±3 (5)          271 ±2 (3)          NA                  123 ±6 (3)          87 ±1 (5)           
depth-2             106 ±1 (4)          100 ±1 (4)          NA                  79 ±3 (4)           36 ±0 (6)           
object-mustache     1318 ±18 (6)        493 ±4 (4)          NA                  NA                  NA                  
object              1185 ±37 (4)        449 ±5 (4)          368 ±2 (5)          180 ±10 (4)         208 ±6 (4)          
partial-recursion   357 ±3 (4)          220 ±3 (5)          24 ±1 (4)           NA                  99 ±1 (3)           
partial             292 ±1 (5)          170 ±4 (4)          136 ±3 (4)          NA                  59 ±0 (5)           
paths               1503 ±20 (6)        715 ±9 (5)          236 ±1 (3)          172 ±10 (3)         101 ±0 (4)          
string              6184 ±78 (4)        5579 ±71 (5)        1114 ±14 (3)        441 ±33 (3)         1833 ±24 (6)        
subexpression       96 ±1 (6)           97 ±0 (5)           NA                  229 ±12 (3)         NA                  
variables           1888 ±28 (5)        1584 ±11 (4)        356 ±3 (5)          167 ±11 (3)         257 ±6 (4)          

https://travis-ci.org/wycats/handlebars.js/builds/34148993#L531

Note sure where exactly this regressed, but it seems to impact all aspects of exec.

@kpdecker
Copy link
Collaborator

(Making the assumption that the travis VMs are comparable in these tests, which might be unsafe)

kpdecker added a commit that referenced this issue Mar 17, 2015
Avoid deoptimizations in v8 due to the duct type check on string instances.

Partial fix for #973
@kpdecker kpdecker added this to the 3.0.1 milestone Mar 17, 2015
@kpdecker kpdecker added the bug label Mar 17, 2015
@kpdecker
Copy link
Collaborator

There were a number of changes that were introduced that caused reduced v8 performance. One of these I was able to mitigate, but the others I was not able to without removing the feature that they are targeting or introducing more code bloat.

ops/msec            handlebars          compat              dust                eco                 mustache
-------------------------------------------------------------------------------------------------------------------
arguments           150 ±1 (4)          131 ±1 (4)          NA                  NA                  NA
array-each          428 ±4 (5)          251 ±2 (4)          325 ±3 (5)          148 ±10 (3)         99 ±4 (6
array-mustache      402 ±3 (4)          247 ±3 (5)          NA                  NA                  NA
complex             229 ±3 (5)          96 ±1 (3)           132 ±1 (6)          91 ±5 (3)           65 ±0 (6
data                150 ±1 (5)          126 ±3 (4)          NA                  NA                  NA
depth-1             268 ±2 (5)          260 ±4 (6)          NA                  147 ±9 (3)          98 ±0 (5
depth-2             102 ±1 (3)          97 ±1 (4)           NA                  96 ±5 (4)           38 ±1 (3
object-mustache     988 ±9 (5)          458 ±5 (5)          NA                  NA                  NA
object              837 ±12 (6)         430 ±5 (4)          418 ±11 (6)         185 ±12 (4)         188 ±2 (6)
partial-recursion   224 ±3 (4)          166 ±2 (6)          19 ±1 (4)           NA                  117 ±1 (5)
partial             180 ±2 (4)          136 ±1 (7)          144 ±1 (6)          NA                  73 ±1 (4
paths               1035 ±16 (4)        782 ±8 (5)          264 ±6 (4)          189 ±12 (4)         107 ±1 (4)
string              6906 ±57 (4)        6662 ±64 (5)        1310 ±41 (4)        474 ±35 (3)         1485 ±16 (5)
subexpression       108 ±1 (5)          113 ±0 (6)          NA                  263 ±17 (3)         NA
variables           1317 ±23 (4)        1195 ±6 (5)         503 ±4 (3)          217 ±13 (3)         281 ±1 (7)

@kpdecker
Copy link
Collaborator

Released in 3.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants