Today I learned

- Thursday, August 21st, we had our first lunch and learn at PubPub. It was held on JS runtimes. Before this meeting, I was pretty ignorant of the difference between node and the V8 engine, let alone did I have a basic understanding of a runtime.

- JS Runtime

-

- JavaScript runtime environments are a group of data structures and packages to run JS. What I find interesting about this design is that runtime environments _include_s useful packages out of the box! These are mostly WebApi standards that are implemented to be used in the JS runtime. Node.js even includes a package manager to use third party libraries in it’s runtime environment. Never did I consider all the things that are just there by default.

- There are 4 parts to a runtime. The engine, event loop, web API, and callback queue.

-

- JavaScript runtime environments are a group of data structures and packages to run JS. What I find interesting about this design is that runtime environments _include_s useful packages out of the box! These are mostly WebApi standards that are implemented to be used in the JS runtime. Node.js even includes a package manager to use third party libraries in it’s runtime environment. Never did I consider all the things that are just there by default.

- There are 4 parts to a runtime. The engine, event loop, web API, and callback queue.

- Javascript engines

- In JS the engine is responsible for calling functions from the stack and storing execution context.

-

- please excuse my horrible writing form

- taken from Geeks](https://www.geeksforgeeks.org/introduction-to-javascript-engines/">Geeks) for Geeks

- I’m not quite sure why each browser needs its own JS runtime, but there are quite](https://en.wikipedia.org/wiki/Comparison_of_JavaScript_engines">quite) a few implementations of web standards so it makes sense because of the complexity of browsers.

-

- In JS the engine is responsible for calling functions from the stack and storing execution context.

-

- please excuse my horrible writing form

- taken from Geeks](https://www.geeksforgeeks.org/introduction-to-javascript-engines/">Geeks) for Geeks

- I’m not quite sure why each browser needs its own JS runtime, but there are quite](https://en.wikipedia.org/wiki/Comparison_of_JavaScript_engines">quite) a few implementations of web standards so it makes sense because of the complexity of browsers.

-

- Web API’s

- We didn’t too much discuss Web API’s. Node.js](https://nodejs.org/en/">Node.js) is the most popular JavaScript runtime and includes](https://nodejs.org/dist/latest-v16.x/docs/api/">includes) a lot of packages out of the box. In the box? Whatever, what Node.js includes are a bunch of libraries that make using web](https://www.javascripttutorial.net/web-apis/">web) standards easy. For instance, node includes an implementation of the sockets](https://nodejs.org/dist/latest-v16.x/docs/api/net.html#class-netsocket">sockets) API.

- We didn’t too much discuss Web API’s. Node.js](https://nodejs.org/en/">Node.js) is the most popular JavaScript runtime and includes](https://nodejs.org/dist/latest-v16.x/docs/api/">includes) a lot of packages out of the box. In the box? Whatever, what Node.js includes are a bunch of libraries that make using web](https://www.javascripttutorial.net/web-apis/">web) standards easy. For instance, node includes an implementation of the sockets](https://nodejs.org/dist/latest-v16.x/docs/api/net.html#class-netsocket">sockets) API.

- Callback Queue

-

- basic event loop from mdn](https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#event_loop">mdn)

- The callback queue contains messages about when to call functions. In the sketch above I drew the basic handling of JS runtimes. The call stack keeps track of the execution context or frame to be called. At some point, a message is sent to the callback queue, and will run until the stack is empty. I’m still confused about this part because it seems the queue also reads from memory and uses the messages to execute functions in a single-threaded way. Mozilla included some links that I will leave here for future me(who reads this right).

- https://stackoverflow.com/questions/2734025/is-javascript-guaranteed-to-be-single-threaded/2734311#2734311

- https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick/#what-is-the-event-loop

-

- basic event loop from mdn](https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#event_loop">mdn)

- The callback queue contains messages about when to call functions. In the sketch above I drew the basic handling of JS runtimes. The call stack keeps track of the execution context or frame to be called. At some point, a message is sent to the callback queue, and will run until the stack is empty. I’m still confused about this part because it seems the queue also reads from memory and uses the messages to execute functions in a single-threaded way. Mozilla included some links that I will leave here for future me(who reads this right).

- https://stackoverflow.com/questions/2734025/is-javascript-guaranteed-to-be-single-threaded/2734311#2734311

- https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick/#what-is-the-event-loop

- Event Loops

-

- The event loop is what keeps track of calls to the stack, message queue, and memory. It’s interesting because heaps,](https://github.com/qweliant/GO-Practice/blob/master/algorithms/24_binary_heap_sort.go">heaps,) queues,](https://github.com/qweliant/GO-Practice/blob/master/algorithms/18_queue.go">queues,) and stacks,](https://github.com/qweliant/GO-Practice/blob/master/algorithms/19_stack.go">stacks,) are the fundamentals of this architecture.

- event loop calling the queue

- That’s about all I’m aware of at current when it comes to runtimes. It’s my nature to compare things, so I will take a look in the future at different runtime environments to see if Frankensteining the best parts of each is something. Or at least to see the influences.

-

- The event loop is what keeps track of calls to the stack, message queue, and memory. It’s interesting because heaps,](https://github.com/qweliant/GO-Practice/blob/master/algorithms/24_binary_heap_sort.go">heaps,) queues,](https://github.com/qweliant/GO-Practice/blob/master/algorithms/18_queue.go">queues,) and stacks,](https://github.com/qweliant/GO-Practice/blob/master/algorithms/19_stack.go">stacks,) are the fundamentals of this architecture.

- event loop calling the queue

- That’s about all I’m aware of at current when it comes to runtimes. It’s my nature to compare things, so I will take a look in the future at different runtime environments to see if Frankensteining the best parts of each is something. Or at least to see the influences.

- Runtime Flavors

- There are also flavors of JS runtimes. We discussed three of them: node, dino, and buns.

- node](https://nodejs.org/en/">node)

- Node.js is the default runtime powering thousands of apps. A few here. Node.js has an early mover advantage, being the first runtime presented to use the google invented v8 engine. The creator, Ryan Dahl, went on to create the next runtime we will discuss.

- deno

- deno is an early-stage runtime environment based on googles V8. Its goal is to provide a more conservative experience for using package modules while including TS support natively. Along with TS it includes, bundling, testing, and linting. deno also allows packages to be hosted anywhere.](https://www.jeremymorgan.com/blog/programming/what-is-deno/">anywhere.)

- buns

- Life begins and ends with buns. So does this post. buns is a spooky fast drop-in runtime replacement for node users. It’s based on Safari’s JS Core WebKit. They rewrote the runtime from scratch in zig.](https://ziglang.org/learn/overview/#small-simple-language">zig.) According to them;

- bun also includes much out-of-the-box for developers including Web API and node package implementations.

- So, this is what I learned from our latest dev meet. It was really nice and I am looking forward to the next one.

-

- There are also flavors of JS runtimes. We discussed three of them: node, dino, and buns.

- node](https://nodejs.org/en/">node)

- Node.js is the default runtime powering thousands of apps. A few here. Node.js has an early mover advantage, being the first runtime presented to use the google invented v8 engine. The creator, Ryan Dahl, went on to create the next runtime we will discuss.

- deno

- deno is an early-stage runtime environment based on googles V8. Its goal is to provide a more conservative experience for using package modules while including TS support natively. Along with TS it includes, bundling, testing, and linting. deno also allows packages to be hosted anywhere.](https://www.jeremymorgan.com/blog/programming/what-is-deno/">anywhere.)

- buns

- Life begins and ends with buns. So does this post. buns is a spooky fast drop-in runtime replacement for node users. It’s based on Safari’s JS Core WebKit. They rewrote the runtime from scratch in zig.](https://ziglang.org/learn/overview/#small-simple-language">zig.) According to them;

- bun also includes much out-of-the-box for developers including Web API and node package implementations.

- So, this is what I learned from our latest dev meet. It was really nice and I am looking forward to the next one.