-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent v8 deopt with a few simple tweaks.
Benchmark script shows a roughly ~40% improvement in model creation.
- Loading branch information
Showing
3 changed files
with
71 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
var State = require('../ampersand-state'); | ||
|
||
function createModel() { | ||
var aModel = State.extend({ | ||
derived: { | ||
foo: { | ||
deps: ['a', 'b'], | ||
fn: function derived () { | ||
return this.a + this.b; | ||
} | ||
} | ||
} | ||
}); | ||
return aModel; | ||
} | ||
|
||
//Function that contains the pattern to be inspected | ||
var aModel = createModel(); | ||
function benchFn() { | ||
return new aModel({a: 1, b: 2}).foo; | ||
} | ||
|
||
function printStatus(fn) { | ||
switch(%GetOptimizationStatus(fn)) { | ||
case 1: console.log("Function is optimized"); break; | ||
case 2: console.log("Function is not optimized"); break; | ||
case 3: console.log("Function is always optimized"); break; | ||
case 4: console.log("Function is never optimized"); break; | ||
case 6: console.log("Function is maybe deoptimized"); break; | ||
} | ||
} | ||
|
||
//Fill type-info | ||
benchFn(); | ||
// 2 calls are needed to go from uninitialized -> pre-monomorphic -> monomorphic | ||
benchFn(); | ||
benchFn(); | ||
benchFn(); | ||
benchFn(); | ||
benchFn(); | ||
|
||
%OptimizeFunctionOnNextCall(benchFn); | ||
//The next call | ||
benchFn(); | ||
|
||
//Check | ||
printStatus(benchFn); | ||
|
||
|
||
console.time('createAModel'); | ||
for (var i = 0; i < 10000;i++) { | ||
benchFn(); | ||
} | ||
console.timeEnd('createAModel'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters