
JavaScript Engine Fundamentals: Shapes and Inline Caches - mariuz
https://mathiasbynens.be/notes/shapes-ics
======
partycoder
Hidden classes and inline caching are very clever ideas. The massive amount of
research and work put into making a language such as JavaScript execute faster
is impressive.

The problem in my opinion is that not all JavaScript code will be efficiently
optimized by these techniques. Some JavaScript code still gets frequently
deoptimized, or optimized to a lesser extent.

The way to prevent that is to learn about these optimizations, which change
often and in undocumented ways, making your code perform very differently
across versions.

Because of this, I found the topic of JavaScript performance to be full of
leaky abstractions (for the JavaScript user). Optimizing JavaScript in
practice can be very, very hard.

~~~
kevingadd
In the past maintainers of the major JS runtimes (v8, etc) have stated they
avoid documenting performance and optimization tips, because people build code
around them and as a result the engine maintainers can't make fundamental
changes without regressing performance of those apps. With how widely some JS
libraries get distributed, you can imagine how this becomes a problem. It's a
nasty situation.

If the difference between a game running at 30fps and 60fps is using weird
optimizations to compensate for quirks in v8 and spidermonkey, you better
believe I'm going to optimize for them. But then script runtime changes later
make my performance tank when other (originally slower) pieces of code speed
up.

~~~
jorisd
One thing I've noticed is that in the past, performance advice was given for
specific engines (e.g. V8/crankshaft). Nowadays, if any performance advice is
given, it's applicable to all major JavaScript engines, and in general the
advice is for developers to write "idiomatic JavaScript", leaving the
optimization to the engines.

~~~
Klathmon
There's a question of what came first there.

I have a feeling those optimizations apply to all engines because they applied
to V8, and maintainers of the other engines attempted to match their
performance since so many were coding for performance on V8 only.

