Skip to content

Instantly share code, notes, and snippets.

@No9
Created July 31, 2012 15:37
Show Gist options
  • Save No9/3217890 to your computer and use it in GitHub Desktop.
Save No9/3217890 to your computer and use it in GitHub Desktop.
Google IO 2012 Breaking the JavaScript Speed Limit with V8

Javascript V8 Optimisations Notes

Notes from Google IO 2012 http://www.youtube.com/watch?v=UJPdhx5zTaw

General

  1. Hidden Classes created at Runtime AS THE CODE EXECUTES
  2. Get your objects to use the same hidden class
  3. Get to know your tools d8 and its options

Construction

  1. Initialise all object members in constructors
  2. Always initialise members in the same order
  3. Don't use dynamic property allocation - new hidden class generated

Numbers

  1. Numbers larger then 31-bit have to be boxed and unboxed

Arrays

Always try to convey to the compiler that you want to use Fast Element instead of Dictionaries

  1. Use contiguous keys and start at 0 or you will be allocated a
  2. Don't allocate large arrays if you don't need it as if you only partially populate it will be a dictionary
  3. Don't delete keys in an array as this causes conversion to Dictionary
  4. Don't read from an uninitialised arrays
  5. Keep the same types in the array

Compilers

Full Compiler

  1. Executes code ASAP with no types but creates Inline Cache
  2. Always pass consistent types (monomorphic over polymorphic) otherwise Inline-Cache is invalidated

Optimizing Compiler

  1. Recompiles hot functions with optimised code using Inlining
  2. try{} catch(){} cannot be optimised move the function outside try catch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment