More Components
In this section, we will be briefly discuss about other important components which are relied by Deno.
V8
V8 is a JavaScript/WebAssembly engine by Google. Written in C++, it is also used most notably in Google Chrome and Node.js.
V8 does not support TypeScript. Instead, all TypeScript code you run in Deno are compiled to JavaScript by a snapshotted TS compiler, while the generated files are stored under .deno
folder. Unless the user updates the code, only the cached JS files would be run after the initial compilation.
FlatBuffers
Flatbuffers is an efficient cross platform serialization library, developed by Google. Flatbuffers allows messages to be passed and accessed across languages without the overhead of parsing and unpacking.
In the case of Deno, FlatBuffers is used to allow intra-process message communication between the privileged and unprivileged sides. Many public Deno APIs internally create buffers that contain serialized data on the TypeScript frontend, and make these buffer available for Rust so that the Rust end could process the request. After completing or scheduling the requests, the Rust end similarly creates buffers for serialized results and sends them back to TypeScript, of which it deserializes them using files generated by FlatBuffers compiler.
In comparison to Node, which creates many V8 bindings for each privileged calls, Deno with FlatBuffers only need to expose message send and receive methods on TypeScript and Rust. This makes adding a new call much easier, and avoids direct interaction with V8.
Flatbuffers is introduced to replace Protocol Buffers in the Go prototype to avoid overhead. See this thread for more information.
Example: Passing readFile Data Through FlatBuffers
TypeScript side:
Rust side:
Tokio
Tokio is an asynchronous runtime for Rust. It is used for creating and handling events. It allows Deno to spawn tasks in a internal thread pool and receive notifications to process the output after the task is complete.
Tokio relies on Rust Future
, which is a construct similar to JavaScript Promises.
Example: Async Task Spawning
In the example of readFile
above, there is a blocking
function. It is used to decide whether a task should be spawned on the main thread or forwarded to the Tokio thread pool.
Last updated