DEV Community

Cover image for Javascript Engine
ikbal arslan
ikbal arslan

Posted on • Edited on

1

Javascript Engine

JavaScript is not directly understood by computers but the browsers have an inbuilt JavaScript engine which helps to convert our JavaScript program into computer-understandable language. So whenever someone talks about running code they are talking about a javascript engine.

Javascript is a dynamic language so we expect it to be slow but it is pretty fast the reason is all the modern runtimes use something called JIT(just in time compile) because of that it is pretty fast.

Here is a list of the javascript engines in some popular browsers:

  • V8 (Chrome)
  • Chakra (Internet Explorer)
  • Spider Monkey (Firefox)
  • Javascript Core Webkit (Safari)

As an example, I will explain the workflow inside of the V8 engine:
for optimizing they use two compilers   

   - baseline compiler ( V8 uses Ignition): it is regular compiler that generates machine code.

   - optimizing compiler (V8 uses turbofan): saves the type information for "hot" functions

Since javascript is a dynamic typing language we don't know the types when a user enters. so the compiler needs to find the types each time. 

For optimization, we use an optimizing compiler which does:

  • Re-compile: (if it is hot or used a lot) "hot" functions with type information from previous execution

  • De-optimize: since javascript dynamically typed language, when the type changes remove it.

If we don't change the types optimizing compiler can remember the types for the same functions so the code can be faster

so if we let the optimizing compiler do its job and don't change the types our code will be much faster.

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more