Getting Started

Get introduced to the concepts we’ll learn in this chapter.

Disadvantages of JavaScript

JavaScript is one of the most popular programming languages. However, JavaScript has two main disadvantages:

  • Unpredictable performance: JavaScript executes inside the environment and runtime provided by JavaScriptengines. There are various JavaScript engines (V8, WebKit, and Gecko). All of them were built differently and run the same JavaScript code in a different way. Added to that, JavaScript is dynamically typed. This means JavaScript engines should guess the type while executing the JavaScript code. These factors lead to unpredictable performance in JavaScript execution. The optimizations for one type of JavaScript engine may cause undesirable side effects on other types of JavaScript engines. This leads to unpredictable performance.

  • Bundle size: The JavaScript engine waits until it downloads the entire JavaScript file before parsing and executing. The larger the JavaScript file, the longer the wait will be. This will degrade our application’s performance. Bundlers such as webpack help to minimize the bundle size. But when our application grows, the bundle size grows exponentially.

Is there a tool that provides native performance and comes in a much smaller size? Yes, WebAssembly.

WebAssembly is the future of web and node development. WebAssembly is statically typed and precompiled, and thus it provides better performance than JavaScript.

Precompilation of the binary provides an option to generate tiny binary bundles. WebAssembly allows languages such as Rust, C, and C++ to be compiled into binaries that run inside the JavaScript engines along with JavaScript. All WebAssembly compilers use LLVMLLVM is not an acronym. When the research project first started, it meant Low-Level Virtual Machine. But later, it was decided to use the name as it is rather than as an acronym. underneath to convert the native code into WebAssembly binary code. As a result, it’s important to understand what LLVM is and how it works.

In this section, we’ll learn what the various components of a compiler are and how they work. Then, we’ll explore what LLVM is and how it helps the compiled languages. Finally, we’ll see how the LLVM compiler compiles native code.