1. Introduction to WebAssembly
Hi, I'm Lynn Clark, and I make code cartoons. I also work at Fastly, which is doing a ton of cool things with WebAssembly to make better edge compute possible. And I'm a co-founder of the Bytecode Alliance. We're working on tools for a WebAssembly ecosystem that extends beyond the browser. And it's one of those tools that I wanted to talk to you about today.
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.
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.
4. Improving Initialization with Snapshotting
Doing things like assembling the Ikea chairs and tables and everything else in the environment before starting the work. Now, this can take considerable time. And that's part of what can make the cold start such an issue for serverless use cases.
Once the initialization phase is done, the JS engine can start its work. This work of running the code. And the speed of this part of the work is called throughput. And this throughput is affected by lots of different variables. So, for example, which language features are being used. Whether the code behaves predictably from the JS engine's point of view. What sorts of data structures are used and whether or not the code runs long enough to benefit from the JS engine's optimizing compiler.
5. Memory Management and Module Separation
Whenever the engine needs a bit of that memory, it can copy the section or rather the memory page that it needs into its own linear memory. With this, the JS engine doesn't have to do any setup when it starts up. All of this is pre-initialized, ready and waiting for it to start its work.
Currently, we attach the data section to the same module as the JS engine, but in the future, once WebAssembly module linking is in place, we'll be able to ship the data section as a separate module. This provides a really clean separation and allows the JS engine module to be reused across a bunch of different JS applications. The JS engine module only contains the code for the engine. That means that once it's compiled, that code can be effectively cached and reused between lots of different instances.
7. Optimization Efforts and Conclusion
From preliminary tests, we can see that the optimization efforts are showing promising results. We still have a lot of work to do to find the clever shortcuts that can be used in this context. If you're excited about this and want to contribute or try to make this work for another language, like Python or Ruby or Lua, we'd be happy to hear from you. Thank you to the organizers for inviting me to speak here today and thank you all for listening.
And from preliminary tests, that percentage seems to hold up for general web browsing as well. Now, this is just one example of a potential optimization that we can make. Right now, we're in the same kind of position that the browser JS engines were in in the early days when they were first experimenting with just-in-time compilers in the first place. We still have a lot of work to do to find the clever shortcuts that we can use in this context. But we're excited to be starting that work and excited for the changes to come.
If you're excited like we are about this and want to contribute to the optimization efforts, or if you want to try to make this work for another language, like Python or Ruby or Lua, we'd be happy to hear from you. You can find us on the messaging platform, Zulip, and feel free to post there if you want to ask for more info. You can also find links to the projects that I mentioned in my recently published blog post on the Bytecode Alliance blog. I want to say thank you to the organizers for inviting me to speak here today and thank you all for listening.
WebAssembly Usage and Q&A
With 55% saying no and 40% saying they want to, it's not surprising that many people are using WebAssembly without realizing it. It's still early in terms of tooling for the ecosystem, but as things progress, more people will start targeting WebAssembly. While it's not widely used in the Netherlands, companies may adopt it in the future. Now, let's move on to the Q&A.
Hi there. Good to see you.
Yeah again, here you're talking more about that people are using it as a consumer but not as a developer.
Yeah. Yeah, it doesn't surprise me at all. I mean, it's even though it's been around for a long time. I actually hop around from client to client every year and I never hear anywhere where it's used yet here in the Netherlands. So, of course, there will be companies but not to my experience. So, it doesn't surprise me.
So, let's jump to the Q&A. We have some questions from our audience, and if you still have any questions for Lynn then you can jump to the Community Track Q&A channel on Discord. I want to make one little note, of course, you make your cartoons, and well, I think everyone here must have fallen in love with your slides, and you will see a big spike in your traffic on the CodeCartoons website. Really great styling of your slides. So, I wanted to give some compliments on that. Thank you. And the CodeCartoons website has not been updated in a while. I need to actually take care of that. So, a great place to find them is the bycode alliance blog or Mozilla's hacks website. And on your Twitter, I think.
WebAssembly's Role in Web Development and Beyond
Yes, and on my Twitter. For the latest and greatest from Lin, check her Twitter.
Next question is from our attendee Keith. What would be a good way to incorporate WebAssembly in an existing application to minimize risk but start to get comfortable using it and taking advantage of it? How to use WebAssembly in an existing project? So it depends on whether or not you're talking about the web or outside of the web. If you're talking about on the web, you probably want to be using an application where if you have something that's computationally heavy, then it makes sense to take that little part that is computationally heavy and port that little bit to WebAssembly. If you're working outside of the web, there are platforms like the one that we have at Fastly where you can just easily put up a WebAssembly module as your, you know, that is the artifact that you put up to run on a computed edge platform. So in that case, you're just going to start up a service doing WebAssembly. And so if you have a microservices architecture, then you can can do one of your services in WebAssembly. Awesome.
Next question is from Warlock.
Build Sizes and Snapshotting in WebAssembly
Build sizes and bandwidth costs of using WebAssembly depend on the application. WebAssembly was designed to be compact, but the size can vary depending on the computation. Snapshotting is possible in V8, but the engine snapshotting is only available with the WebAssembly runtime. To learn more about WebAssembly, check out my blog posts on the Mozilla Hacks website or the Bike Reliance site.
Last question we have time for. And before ... I have to sneeze. Sorry. Okay. I got it. I got it. Next question is from Bartos. Is snapshotting possible with V8 too, or has it only been explored in the context of WASM? So I think one thing that people sometimes don't realize is the snapshotting that you have in V8, that is applications. And this is something that ... That part is not new. Application snapshotting is not new. The snapshotting the engine is something that you wouldn't have without the WebAssembly runtime to do that snapshotting. Because if you're opening up a V8 isolate, what you're starting up is the isolate itself. So that engine initialization is also part of this. All right. Awesome. So that was the last question. But I have one question that I feel is too important to skip. And it's from Richard S. And he says, where can I learn more about WebAssembly? So I've done a number of blog posts about WebAssembly. You can find those on the Mozilla Hacks website or on the Bike Reliance site.
Resources and Q&A
You can find more information on the Mozilla Hacks website or the Bike Reliance site. If you want to get involved in WebAssembly, there's a GitHub repo where all the standardization happens. Join Lin on Spatial Chat for further discussions.
You can find those on the Mozilla Hacks website or on the Bike Reliance site. If you want to get involved in WebAssembly, there's a GitHub repo where all the standardization happens. That's if you really want to get low level deep into the details.
Nice. All right. Thanks, Lovely. So there's some more questions in the Discord channel that we don't have time for. But I will invite everyone that still has questions for Lin to join Lin on a room on Spatial Chat, where she will be going now. So Lin, thanks a lot for joining me here and enjoy your Spatial Chat Speaker Room. Thank you. See y'all.