Share
Embed
Deno: an experimental approach on V8 interoperability
Matias Insaurralde
October 20, 2018
Transcript
42 slides
-
Intro • 23 years old, living in Asunción, Paraguay !
• Engineer at (we’re building an open source API gateway!). • I love FOSS and security topics. • Hobbies: meet random people, improvise music, eat pasta. -
Agenda • Overview of NodeJS syscalls. • What’s deno? •
Go versus Rust: interop constraints • My HTTP experiment • What’s next? -
What’s deno? • It’s a TypeScript runtime focused on security,
built on V8. • No explicitly compatible with NodeJS (also: no npm, no package.json, etc.). • The initial prototype used a Golang backend, current one is written in Rust. C++ is used in a minimal way to bind V8 to these alternative backends. -
What’s deno? • Network access, local FS access and env
access disabled by default. • Syscalls are easier to audit and could provide a good security framework for some applications. • Minimal number of V8 interactions: send, recv (used for in-memory message passing). -
deno.readFileSync(…) (TS wrapper/V8) ReadFileSync(…) (Golang) open(…) (posix) fs.readFileSync(“file.txt”) fd =
fs.openSync(“file.txt”, …) binding.open(…) (node_file.cc) uv_fs_open(…) (libuv) open(…) (posix) deno node -
in-memory pubusb message passing fs.readFileSync(“file.txt”) deno.readFileSync(…) (TS wrapper/V8) ReadFileSync(…) (Golang)
open(…) (posix) Golang V8 Channels os deno.readFileSync(…) Publishes a message containing the filename and other parameters. -
in-memory pubusb message passing fs.readFileSync(“file.txt”) deno.readFileSync(…) (TS wrapper/V8) ReadFileSync(…) (Golang)
open(…) (posix) Golang V8 Channels os deno.readFileSync(…) Publishes a message containing the filename and other parameters. After receiving the message, the dispatcher calls ReadFileSync(…) -
in-memory pubusb message passing fs.readFileSync(“file.txt”) deno.readFileSync(…) (TS wrapper/V8) ReadFileSync(…) (Golang)
open(…) (posix) Golang V8 Channels os ReadFileSync(…) Reads the file and publishes a message to the “os” channel, containing the file contents. We get the file contents! -
in-memory pubusb message passing fs.readFileSync(“file.txt”) deno.readFileSync(…) (TS wrapper/V8) ReadFileSync(…) (Golang)
open(…) (posix) Golang V8 Channels os net http The runtime can implement different channels for each required module. The messages are serialized using Protocol Buffers*. -
in-memory pubusb message passing fs.readFileSync(“file.txt”) deno.readFileSync(…) (TS wrapper/V8) ReadFileSync(…) (Golang)
open(…) (posix) Rust V8 Channels os net http -
Golang vs Rust: interop constraints • Go is a GCed
language and doesn’t allow passing Go pointers to the native side (the opposite is possible though), this might result in unnecessary allocations under some circumstances. • Using deno with a Go backend involved two GCs! This is a potential issue ry mentioned and one of the reasons to replace Go with Rust, which it’s not GCed. -
Golang vs Rust: interop constraints • deno was able to
start multiple V8 workers but there’s no easy way of accessing these workers from the Go side, a “worker table” was used, involving a mutex as you can find in: https:// github.com/ry/v8worker2 • I did a Rust port of this library to continue my experiment: https://github.com/ matiasinsaurralde/rust-v8worker2 -
Golang vs Rust: interop constraints • The Rust port is
way more efficient as you can handle interactions with the native world easily and keep passing pointers! • This is what my port looked like: -
Golang vs Rust: interop constraints • This is my hacky
reimplementation of deno in rust (it’s called reno): https://github.com/matiasinsaurralde/reno -
My HTTP experiment • I began researching the architecture and
initial implementation after the project was announced in JSConf (June 6, 2018). • The initial implementation used Golang and a simple dispatcher (very similar to the current one). -
What’s next? • The current implementation uses a new Rust
backend. • Everything is contained on a single binary (a minimal V8 build is embedded into this). • Roadmap here: https://github.com/ denoland/deno/blob/master/Roadmap.md -
What’s next? • The current implementation replaced Protocol Buffers with
Flatbuffers: this is a great thing in terms of memory usage! • Browser compatibility is planned. • Experimental binaries are being released from time to time (Linux, Windows and OS X). -
What’s next? • Current implementation uses Tokio, an async runtime
for Rust, replacing libuv in some ways. • HTTP support using the new Rust backend is in progress… -
Thanks! Find deno here: https://github.com/denoland/deno Find me on: Twitter: @matias_baruch
Github: matiasinsaurralde E-mail: [email protected]