Skip to content

Instantly share code, notes, and snippets.

@fhinkel
Last active November 17, 2016 10:34
Show Gist options
  • Save fhinkel/965e778d27cd39a943a855003fde6aea to your computer and use it in GitHub Desktop.
Save fhinkel/965e778d27cd39a943a855003fde6aea to your computer and use it in GitHub Desktop.
var fs = {
readFile: function(filename, cb) {
cb(null, {length: 12});
}
}
for (var i = 0; i < 10000; i++) {
var __filename = 'perf-test.js';
printLength(__filename)
}
function printLength (filename) {
fs.readFile(filename, foo)
function foo (err, buf) {
if (err) return // ignore error - probably just too many fds
for (var j = 0; j<1000; j++) {
// Do some work to make the optimization actually worth while
buf.length++;
}
return (filename + ' has length ' + buf.length);
}
}
@fhinkel
Copy link
Author

fhinkel commented Nov 17, 2016

Adapted from https://gist.github.com/fhinkel/42bebdaa56bc7fca537aae8c5518c245 to work without Node.js.

./out.gn/x64.debug/d8 perf-test.js --trace-opt --mark_shared_functions_for_tier_up
[marking 0x38ee89b2ba81 <JS Function printLength (SharedFunctionInfo 0x38ee89b2b581)> for optimized recompilation, reason: small function, ICs with typeinfo: 3/4 (75%), generic ICs: 0/4 (0%)]
[compiling method 0x38ee89b2ba81 <JS Function printLength (SharedFunctionInfo 0x38ee89b2b581)> using Crankshaft]
[marking 0x254cc8b1cb21 <JS Function foo (SharedFunctionInfo 0x38ee89b2c0a9)> for optimized recompilation, reason: small function, ICs with typeinfo: 4/4 (100%), generic ICs: 0/4 (0%)]
[optimizing method 0x254cc8b1cc41 <JS Function foo (SharedFunctionInfo 0x38ee89b2c0a9)> eagerly (shared function marked for tier up)]
[compiling method 0x254cc8b1cc41 <JS Function foo (SharedFunctionInfo 0x38ee89b2c0a9)> using Crankshaft]
[optimizing 0x254cc8b1cc41 <JS Function foo (SharedFunctionInfo 0x38ee89b2c0a9)> - took 0.516, 2.167, 0.544 ms]
[optimizing 0x38ee89b2ba81 <JS Function printLength (SharedFunctionInfo 0x38ee89b2b581)> - took 0.399, 1.379, 0.189 ms]
[completed optimizing 0x38ee89b2ba81 <JS Function printLength (SharedFunctionInfo 0x38ee89b2b581)>]
[marking 0x38ee89b2b869 <JS Function (SharedFunctionInfo 0x38ee89b2b359)> for optimized recompilation, reason: small function, ICs with typeinfo: 9/12 (75%), generic ICs: 0/12 (0%)]

For progress, see https://bugs.chromium.org/p/v8/issues/detail?id=5512#c34.

@fhinkel
Copy link
Author

fhinkel commented Nov 17, 2016

~/v8 (master)$ time ./out.gn/x64.debug/d8 perf-test.js --mark_shared_functions_for_tier_up
real	0m0.385s
user	0m0.368s
sys	0m0.020s
~/v8 (master)$ time ./out.gn/x64.debug/d8 perf-test.js 
real	0m1.533s
user	0m1.515s
sys	0m0.026s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment