It's very interesting because there was an article just a couple of days ago saying that, you know, the old phones that we dismiss because we don't even like them and there are new ones coming up, they just don't disappear. They kind of get in past three generations. So you end up maybe, you know, second generation, third generation, they're still being used. And if you're using a heavy application today, this is going to be just a horrible experience.
So maybe to just really break it down into kind of strategic parts. So if you have a legacy application and you want to make it fast and you realize that you have some issues with the thread, how do you decide what should go into WebWorker, what should go into Worklet, what should go into WebAssembly? What's your strategy? Yes, this is a very, very good question. So I often ask the question that right now you're asking. It's a bit broad to answer, though, but I try to simplify it a little bit and answer it. So what I do usually, I just give my personal experience, is that, like you said, so I try to actually run my application first on a very low-level device and then try to figure out which part of the application needs a little bit of improvement, right? So, and depends on that improvement, I decide like, should this one goes to WebWorker or should this one goes to Worklet, for instance, using Worklet. Let's say, as an example, so I gave an example about Redux, right? So sometimes it happens, you know, you have a synchronous operation in your application and see that you're just running some JavaScript code and it's just some execution. And then you feel like, okay, this is blocking my event loop for a while. So, and then it's blocking my UI, right? So probably this is a good candidate to move it there. But then you go to another part of your application and see that, oh, this is like a background that I render, you know, and well, the rendering causes a little bit of janky frame when the animation is running, right? Then I think, oh, then we have another API worklet to render these low-level format of rendering like graphic and audios, right? Then I decided to move that to worklet instead of doing that in WebWorker. Or then sometimes you feel that like, okay, well, you can definitely use, I actually had an example in the talk. So you can definitely use some JavaScript libraries, for instance, and decode or encode or compress like some data or images or videos and stuff, you know, in your application, for sure. But then that's probably the part you think that, oh, this part, probably there are some better libraries in C or maybe some libraries have been written in ROS, and then I can actually compile it to WebAssembly. So this is very important, actually. When we are talking about these APIs, it's very, very important you just talk about which part of the application you have a problem. So, and then you need to figure out based on that, which one is closer to the API that you need to use, you know? But I usually do it this way.
Yeah, that definitely makes sense, and it's really interesting that we have all these options available, right, and so we can actually make use of them. And it's probably, you know, every single sophisticated application will probably use a very interesting combination, hybrid combination of all those things.
There were also many questions coming up in the chat. One of them was Jay Holfeld, I guess. And Jay would like to know, what's the trade-off between spawning a Web Worker and actually doing the work? Is using Web Workers worthwhile, even for minimal tasks? Yes, first of all, hi, Jay. Very good question. If you pay attention to one of my slides, I said that there is a little bit of overhead when you are actually spawning a Web Worker. So technically, you're adding a little bit of work to your application or workload, let's say. So there is a trade-off, for sure. But then, do you have to use Web Worker for everything? Okay, today I learned that there is a library that I can simply just use it and then it's synchronized. Like, it's the way that I write my JavaScript.
Comments