/ GARBAGE COLLECTOR, GOOGLE CHROME, JAVASCRIPT, PERFORMANCES, TALK

Notes about JavaScript code optimisation

A couple of days ago YouTube suggested me this video about optimising JavaScript games on Google Chrome. The video is a talk from the GDC 2012 so it’s pretty old (2 years in IT’s time is really a lot) but the content of the talk is still valid today and in the near future.

The talk is about game’s code optimisation but some of the techniques and good practices should be used also in everyday’s JavaScript code:

By the way here my personal list of some of the topics I considered interesting:

  • Integers: differences in storage and performances between 31-bit (or 32-bit n x64 architectures) integers and 64-bit integers; usually this is not an issue but it’s good to know just in case your code is handling very big natural numbers

  • Arrays: differences between typed and JavaScript arrays and about the latter differences in storage size and access speed

  • Object model: JavaScript optimise the access to attributes and functions of a class by compiling the class’ code into machine code; this means if you alter the class by adding or removing attributes outside the constructor the JavaScript engine will throw away the optimised code reducing the performances

  • Garbage collection: short story use short lived or long lived objects, long story watch the video :-)

  • RequestAnimationFrame (RAF): on animations avoid the usage of setTimeout() and use requestAnimationFrame() instead