Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Deno: an experimental approach on V8 interoperability

Deno: an experimental approach on V8 interoperability

Matias Insaurralde

October 20, 2018
Tweet

More Decks by Matias Insaurralde

Other Decks in Programming

Transcript

  1. 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.
  2. Agenda • Overview of NodeJS syscalls. • What’s deno? •

    Go versus Rust: interop constraints • My HTTP experiment • What’s next?
  3. 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.
  4. 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).
  5. 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
  6. 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.
  7. 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(…)
  8. 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!
  9. 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*.
  10. 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.
  11. 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
  12. 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:
  13. Golang vs Rust:
 interop constraints • This is my hacky

    reimplementation of deno in rust (it’s called reno):
 https://github.com/matiasinsaurralde/reno
  14. 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).
  15. 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
  16. 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).
  17. 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…