But more than this, platforms that use these kinds of techniques to hide latency also often reuse instances between requests. And in some cases, this means that global state can be observed between different requests, which can be a security issue. And because of this cold start problem, developers also often don't follow best practices.
They stuff a lot of functions into one serverless deployment. So, this results in another security issue, which is a larger blast radius. If one part of the serverless deployment is exploited, the attacker has access to everything in that deployment. But if we can get JavaScript startup times low enough in these contexts, then we wouldn't need to hide startup times with any tricks. We could just start up an instance in microseconds.
With this, we can provide a new instance for each request, which means that there's no state lying around between requests. And because the instances are so lightweight, developers could feel free to break up their code into fine-grained pieces. And this would bring their blast radius down to a minimum for any single piece of code. So, for these use cases, there's a big benefit to making JavaScript on WASM fast. But how can we do that?
In order to answer that question, we need to understand where the JavaScript engine spends its time. We can break down the work that a JavaScript engine has to do into two different parts. Initialization and runtime. I think of the JS engine as a contractor. This contractor is retained to complete a job, and that job is running the JavaScript code and getting to a final result.
Before this contractor can actually start running the project, though, it needs to do a little bit of preliminary work. This initialization phase includes everything that only needs to happen once at the very start of the project. So, one part of this is application initialization. For any project, the contractor needs to take a look at the work that the client wants it to do and then set up the resources that it needs in order to complete that job. So, for example, the contractor reads through the project briefing and other supporting documents and turns them into something that it can work with.
So, this might be something like setting up the project management system with all of the documents stored and organized and breaking things into tasks that go into the task management system. In the case of the JS engine, this works more like reading through the top level of the source code and parsing functions in the byte code, or allocating memory for the variables that are declared and setting values where they're already defined. So, that's application initialization. But in some cases, there's also engine initialization. And you see this in contexts like serverless. The JS engine itself needs to be started up in the first place. And built-in functions need to be added to the environment. I think of this like setting up the office itself.
Comments