Skip to content

Instantly share code, notes, and snippets.

View mraleph's full-sized avatar
🐌

Slava Egorov mraleph

🐌
View GitHub Profile
import 'dart:async';
import 'dart:html' as html;
stream() {
final sc = new StreamController();
spawn(ms, id) =>
new Timer.periodic(new Duration(milliseconds: ms), (_) => sc.add(id));
spawn(250, 1);
@mraleph
mraleph / test.asm
Last active December 20, 2015 16:09
--- Optimized code ---
kind = OPTIMIZED_FUNCTION
name = foo
stack_slots = 1
Instructions (size = 90)
0x48634f60 0 55 push ebp
0x48634f61 1 89e5 mov ebp,esp
0x48634f63 3 56 push esi
0x48634f64 4 57 push edi
0x48634f65 5 6a00 push 0x0
;;; <@80,#66> -------------------- B5 (loop header) --------------------
;;; <@83,#68> compare-numeric-and-branch
0x598365b8 408 3bc3 cmp eax,ebx
0x598365ba 410 0f8d6f000000 jnl 527 (0x5983662f)
;;; <@88,#75> -------------------- B7 --------------------
;;; <@90,#77> stack-check
0x598365c0 416 3b251c691e09 cmp esp,[0x91e691c]
0x598365c6 422 0f8282000000 jc 558 (0x5983664e)
;;; <@92,#79> check-non-smi
0x598365cc 428 f6c101 test_b cl,0x1
$ cat test.js
function foo () { while (true) { } }
function bar () { return foo(); }
bar();
$ node test.js &
$ gdb attach $(pidof node)
0x00000bf778c63d5f in ?? ()
(gdb) b v8::internal::Runtime_StackGuard
Breakpoint 1 at 0x84a1f0
(gdb) print 'v8::V8::TerminateExecution'(0)
var pi = (function () {
var NTP = 25;
var tp = [];
tp[0] = 1.;
for (var i = 1; i < NTP; i++) tp[i] = 2. * tp[i-1];
function series(m, id) {
var s = 0;
var eps = 0.00000000000000001;
--- Optimized code ---
kind = OPTIMIZED_FUNCTION
name = f138178145338511
stack_slots = 1
Instructions (size = 58)
0x5cacb8a0 0 55 push ebp
0x5cacb8a1 1 89e5 mov ebp,esp
0x5cacb8a3 3 56 push esi
0x5cacb8a4 4 57 push edi
0x5cacb8a5 5 6a00 push 0x0

Making iteration faster in Array built-ins.

Lets imagine we have forEach method. The core loop of this method in V8 is implemented in JavaScript and looks like this:

for (var i = 0; i < length; i++) {
  if (i in array) {
    var element = array[i];
    %_CallFunction(receiver, element, i, array, f);
 }
function BenchmarkRun() {
// Benchmark.prototype.setup goes here
obj = {
"apples": true,
"oranges": true,
"pears": true,
"pinapples": true,
"grapes": true,
}
array = [
function B1() {
// Benchmark.prototype.setup goes here
var str = '1.1';
var start = new Date;
for (...) { // do N iterations of test body
str++;
}
var end = new Date;
};