Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Performance

Against V8

samples/benchv8 (j8 with its JIT, --runs 10, pinned to performance cores, load below 1). All 11 benchmarks produce matching checksums on the three engines.

Benchmarkj8 msV8 jitless msV8 msj8 / jitlessj8 / V8
fib1.29.01.30.1×0.9×
loop58.3185.082.80.3×0.7×
objects0.913.62.50.1×0.4×
array40.813.06.53.1×6.3×
sort65.832.116.52.1×4.0×
string27.811.711.32.4×2.5×
closures2.117.22.30.1×0.9×
classes1.423.32.80.1×0.5×
collections52.827.921.31.9×2.5×
json24.911.611.52.2×2.2×
regexp12.43.01.84.2×7.0×
Geometric mean0.6×1.7×

(A ratio below 1 means j8 is faster. From samples/benchv8/benchmark.md; the repository has the current numbers.)

What the JIT does for them

  • fib: a native function per JS function, called directly (arguments in registers, results unboxed through a second return register), the recursive call inlined two levels deep; the global fib read through an epoch cache;
  • closures: the closure inlined into the loop (checked by function identity), its context slots in registers, % 100000 as a multiplication;
  • classes / objects: constructors and methods inlined, objects that don’t escape never allocated (fields as values, across loop iterations too: the loop entered on-stack is peeled once), shape checks and loads hoisted out of the loop;
  • loop: (s + i * i) % 1000003 with i * i past int32 runs as an int64 remainder of doubles.

array, sort, string, collections, json and regexp spend their time in built-ins (and the GC); the JIT doesn’t help them yet, and they are next.

Measuring

  • timing covers compile + execute, a fresh environment per run, the shortest kept;
  • pin to performance cores (taskset -c 0-3) and run with low load;
  • judge a change by all the benchmarks, not just the one it targets;
  • callgrind for line-level hot spots; perf stat -e instructions:u for instruction counts.