-
All of the code that runs on startup and all of the code the code that interfaces with V8 is compiled from Rust, but all of code that interacts with JS is... JS. I'm talking about code such as the V8 startup snapshot, and all of the builtins not provided by V8. Can't they be written in Rust too? Most, if not all of Chromium's builtins are written directly in C++ (iirc there is a small bit of Rust too). Writing the builtin code in Rust would provide much more predictable performance, memory usage, would be much safer, and would avoid "stupid" bugs, such as JavaScript prototype manipulation, as Rust/C++ would be able to directly interface with V8 to get information about objects passed in from the JS context. Also doesn't JSON serialization-deserialization alone on every call to send/recv add unnecessary overhead? Was there any explicit reasoning for the current decision to have used as much JS as is currently being used? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Writing in Rust and injecting into the isolate is obtuse, especially for complex APIs. It is easier and faster to write these in JavaScript. Quite a lot of Node.js's runtime is written in JavaScript.
Most of the web standard runtime constructs don't op out to Rust. They stay totally within the isolate. Those that do, do at the edge, the "hot path" where they have to bind with the local system.
The core team generally has made a conscious decision when dealing with implementing an API, but we have always avoided injecting objects into the isolate where we can avoid it. An example of iteration over time is |
Beta Was this translation helpful? Give feedback.
-
A bad assumption in my opinion. Having done some of the big APIs in Deno, I can assure you it is a lot easier in JavaScript.
It can, but if we were really worried about that we would grab references to those globals when the code innited. So there are ways to address this. @bnoordhuis has mentioned this in passing and we have discussed freezing intrinsics before, but why take that tool out of users hands plus cause web compliance issues. I am just not sure this is more of a worry. Streams does now do some of this, but the motivation was more out of compliance with the spec. There is a reason Deno has a security model outside of the sandbox. Poisoning typed array wouldn't only break built in code, but pretty much every userland program. So having one bit of code "safe" while everything else is broken buys you once? We have a lot of tools outside the sandbox to ensure what gets in there is predictable and wanted with a backstop of a 0 trust permission system. |
Beta Was this translation helpful? Give feedback.
A bad assumption in my opinion. Having done some of the big APIs in Deno, I can assure you it is a lot easier in JavaScript.
It can, but if we were really worried about that we would grab references to those globals when the code innited. So there are ways to address this. @bnoordhuis has mentioned this in passing and we have discussed freezing intrinsics before, but why take that tool out of users hands plus cause web compliance issues. I am just not sure this is more of a worry. Streams does now do some of thi…