Kyle Edwards

JavaScript Internals

JavaScript is implemented from the EcmaScript Standard defined by the TC39 committee.

Compilation

JavaScript generates machine code during runtime using just-in-time (JIT) compilation (versus ahead-of-time (AOT) compilation). JavaScript engines (V8, SpiderMonkey, Chakra, etc…) implement one or more separate optimizing compilers to recompile hot functions as they obtain more type information. If the type information continues to change, optimizing compilers must continually deoptimize and reoptimize, which can hurt performance.

Object types are represented internally as an object and their properties. If properties are not added in the same order, they are technically different types.

I imagine using a statically typed superset or transpiled language like TypeScript or Elm can only improve performance in this regard.

Node.js Flags for Viewing Compilation

--print-opt-code
--print-bytecode
--trace-ic
--trace-opt
--trace-depot

Resources