Foundation: Engines & Compilers Flashcards
What is deno
Deno is a simple, modern and secure runtime for JavaScript and TypeScript that uses V8 JavaScript engine and the Rust programming language.
What is Global execution context?
The global execution context is the default or first execution context that is created by the JavaScript engine before any code is executed(i.e, when the file first loads in the browser). All the global code that is not inside a function or object will be executed inside this global execution context. Since JS engine is single threaded there will be only one global environment and there will be only one global execution context.
What is function execution context?
Whenever a function is invoked, the JavaScript engine creates a different type of Execution Context known as a Function Execution Context (FEC) within the Global Execution Context (GEC) to evaluate and execute the code within that function.
What is nodejs
Node.js is a server-side platform built on Chrome’s JavaScript runtime for easily building fast and scalable network applications. It is an event-based, non-blocking, asynchronous I/O runtime that uses Google’s V8 JavaScript engine and libuv library.
What is an event loop
An event loop is a core concept in asynchronous programming and is central to how JavaScript handles non-blocking operations. It’s a mechanism that allows JavaScript to execute code in a non-blocking and efficient manner, particularly in web browsers and Node.js environments.
Here’s a brief overview of how an event loop works:
- Event Queue: JavaScript maintains an event queue (also known as a message queue) where events like user input, network requests, or timers are placed when they occur.
- Execution Stack: JavaScript also has an execution stack (call stack) where function calls are stacked as they are executed.
- Event Loop: The event loop continuously checks the event queue while the execution stack is empty. When the stack is empty, it takes the first event from the queue and pushes it onto the stack for execution.
- Non-Blocking: If the event being processed involves a time-consuming operation, like an asynchronous function or a network request, it doesn’t block the entire program. Instead, the event loop moves on to the next event in the queue.
- Callback Functions: Asynchronous operations often involve callback functions. When an asynchronous task completes (e.g., a file is read or a network request finishes), its associated callback is placed in the event queue for later execution.
- Repeat: This process repeats indefinitely, allowing JavaScript to handle multiple concurrent tasks and respond to events as they occur without freezing the application.
In essence, the event loop enables JavaScript to manage concurrency by efficiently handling asynchronous operations and ensuring that the application remains responsive even when dealing with tasks that may take some time to complete.
This concept is fundamental to understanding how JavaScript handles events, timers, and asynchronous operations, making it a crucial part of web development and other environments where JavaScript is used.
What is V8 JavaScript engine
V8 is an open source high-performance JavaScript engine used by the Google Chrome browser, written in C++. It is also being used in the node.js project. It implements ECMAScript and WebAssembly, and runs on Windows 7 or later, macOS 10.12+, and Linux systems that use x64, IA-32, ARM, or MIPS processors. Note: It can run standalone, or can be embedded into any C++ application.
What is Javascript Engine?
A JavaScript engine is a software component that executes JavaScript code. The first JavaScript engines were mere interpreters, but all relevant modern engines use just-in-time compilation for improved performance
What is happening inside JS Engine?
What does Parser do in Javascript Engine?
It checks for syntax and semantics. Parser is nothing but a lexical analysis that results into the breaking of code into tokens in order to understand their meanings and these tokens gets converted into Abstract Syntax Tree(AST).
What is lexical analysis?
Lexical Analysis is the first phase of the compiler also known as a scanner. It converts the High level input program into a sequence of Tokens.
Tokens: A lexical token is a sequence of characters that can be treated as a unit in the grammar of the programming languages.
Example of tokens:
Type token (id, number, real, . . . )
Punctuation tokens (IF, void, return, . . . )
Alphabetic tokens (keywords)
What is Abstract Syntax tree?
It is a hierarchical tree like structure of program representation which allows interpreter to understand the program.
This AST is initially goes to the Interpreter.
What is Interperter?
It let’s the AST to get converted into Byte code.
In V8 engine, this process is known as Ignition but when some code gets repeated again and again.
What happens when you run?
In the above code, we are calling multiply() function 1000 times. When this code goes into the interpreter, the interpreter performance got decreased, since, Interpreter had to repeat this code again and again and then profiler will mark this code as warm and comes into action.
What is Profiler?
It will check for the repeating code that can be optimized. As soon as, it gets the repeating code, it basically moves the code into compiler.
What is compiler?
It spits out the most optimized byte code.