1. 11
  1.  

    1. 3

      My first thought was that this is a hack to game the benchmark; but it’s a legit optimization that probably has an overall benefit, just less noticeable than in that one benchmark.

      I’ve been coding in TypeScript lately and wondering about what kinds of optimizations the JSVM is doing on my code. Coming from C++ I’m used to doing that! Anyone know of any good documentation of JS performance advice? (Not browser-specific stuff, but core JS.)

      1. 2

        After years programming JS and reading all the JSVM blog posts I still have little idea what the compiler is doing behind the scenes. If you ever find a good resource like you describe I’d love to hear about it.

        For whatever it’s worth this is my advice:

        1. Avoid allocating. This is true in all languages but in JS it feels especially easy to do something an allocation heavy way without thinking about it. Something about the object literal syntax. And as this blog post describes apparently setting an integer variable can allocate behind the scenes (!!!)

        2. Use simple classes or objects with fixed field types & order so your stuff turns into “hidden class” struct access behind the scenes instead of hash tables.

        3. Simple string math is often the most optimized path for building up a string let result = “”; while (stuff) result += “things” because JSVM wizardry.

        4. As the article seems to suggest, JSVMs spend a lot of time trying to make int31 or int32 fast as well as arrays of those types.

      2. [Comment removed by author]