# How V8's compilation cache supports function inlining

DevFeed: [How V8's compilation cache supports function inlining](<https://devfeed.tech/articles/a-mythical-beast-called-jit-22364.md>)

Original publisher: [Read original article](<http://www.afronski.pl/2016/04/08/a-mythical-beast-called-jit.html>)

Author: Wojtek Gawroński (afronski)

Published: 2016-04-08T17:45:00Z

Content type: article

Language: en

Sources: [Wojtek Gawroński](<https://devfeed.tech/sources/wojtek-gawronski.md>)

Topics: [Compiler](<https://devfeed.tech/topics/compiler.md>), [V8](<https://devfeed.tech/topics/v8.md>), [JavaScript](<https://devfeed.tech/topics/javascript.md>), [JIT](<https://devfeed.tech/topics/jit.md>), [Optimization](<https://devfeed.tech/topics/optimization.md>), [Node.js](<https://devfeed.tech/topics/node-js.md>)

Tags: [article](<https://devfeed.tech/tags/article.md>), [c-sharp](<https://devfeed.tech/tags/c-sharp.md>), [cache](<https://devfeed.tech/tags/cache.md>), [canvas](<https://devfeed.tech/tags/canvas.md>), [clojure](<https://devfeed.tech/tags/clojure.md>), [compilation](<https://devfeed.tech/tags/compilation.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [css](<https://devfeed.tech/tags/css.md>), [css3](<https://devfeed.tech/tags/css3.md>), [erlang](<https://devfeed.tech/tags/erlang.md>), [html](<https://devfeed.tech/tags/html.md>), [html5](<https://devfeed.tech/tags/html5.md>), [inlining](<https://devfeed.tech/tags/inlining.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [mono](<https://devfeed.tech/tags/mono.md>), [net](<https://devfeed.tech/tags/net.md>), [node-js](<https://devfeed.tech/tags/node-js.md>), [optimization](<https://devfeed.tech/tags/optimization.md>), [sicp](<https://devfeed.tech/tags/sicp.md>), [v8](<https://devfeed.tech/tags/v8.md>), [vagrant](<https://devfeed.tech/tags/vagrant.md>), [webgl](<https://devfeed.tech/tags/webgl.md>)

## AI overview

This article explains why just-in-time compilation in V8 is difficult for JavaScript and discusses compilation caching as an optimization technique related to function inlining. It distinguishes compilation caches from inline caches.

## Source excerpt

A mythical beast called JIT I have recently bumped into one of those articles which title sounds rather like "one weird trick" ad. Guiding just from it, you can imagine how small amount of information is contained there, and by actually going through that link there you will definitely make sure that it has some knowledge, but no real explanations are in place. Of course, a final explanation is indeed really simple - Function.prototype.toString() returns everything even the comments inside the function body, size of that string is a feature that allows the optimizing compiler inside V8 to make a decision to inline that particular function or not. There is even a command line switch which to use to modify a limit and a default value. Simple enough? Not really. That article left a lot of unanswered questions. Probably because of that JIT compilers and its optimization techniques are kind of black magic. Why is it hard? Obviously compiler engineers are not dumb people (they are actually really smart) and they are not obfuscating and complicating this by accident or on purpose. They are working hard, especially with such weakly typed and underspecified languages like JavaScript to provide you an optimized version of your code. Why is it a hard job? It is all about guarantees. How many of them you can recall from memory when it comes to JavaScript? Not a lot of them, right? That is not good, especially from the perspective of a compiler engineer. JavaScript is everywhere, success of the internet spread this language, and nowadays success of Node.js pushed this language from front-end, even to server-side - and everywhere people are talking about performance. Obviously not about native like performance for scientific computations, but the more complexity is pushed to the application layer, the more of it will have to be optimized after all. That's why compilers and their creators have to be smart people - they have to deal with complexity of your applications and "illness