The Trash Performance of JavaScript.

Why interpreted language like JavaScript are slow explained using diagram.

Jay
2 min read1 day ago

JavaScript

Anyone who has written a fair bit of JavaScript/Typescript and any other compiled language understands the enormous performance difference between the two.

Experienced developers would describe performing intensive tasks such as 3D Rendering using JavaScript like cutting trees with a knife.

The main reason for JavaScript’s slowness lies in its architecture. As an interpreted language, JavaScript is not compiled ahead of time (AOT). Instead, it is compiled and interpreted simultaneously by its interpreter.

Type Inference

Moreover, JavaScript is not a statically-typed language, meaning its engine must perform type inference.

Type inference involves the compiler determining the type of a variable on its own, which requires additional time and can contribute to JavaScript’s slower performance.

Garbage Collection

A garbage collector is a program that runs separately from the main program and momentarily checks for unused memory to clean it up.

JavaScript’s V8 engine has a garbage collector known as Orinioco. This garbage collector introduces overhead and contributes to the slow performance of JavaScript.

In Contrast

In contrast, compiled languages like C are significantly faster than JavaScript, by orders of magnitude in certain use-cases (like 3D rendering). This increased speed can be attributed to several factors:

  • Compiles directly to binary/machine code.
  • Lacks a garbage collector, avoiding pauses for memory management.
  • Is statically typed, eliminating the need for runtime type checking or inference.
  • Doesn’t rely on a runtime engine, interpreter, or any additional programs that could introduce overhead.

--

--