[Weekend Drop] Miško Hevery: Qwik, PartyTown, and Lessons from Angular

Download MP3
I chat with Miško Hevery about his view of where web tooling needs to go to solve the slow website problem once and for all.
This podcast involves two live demos, you can catch up on the YouTube verison here: https://youtu.be/T3K_DrgLPXM

Links

Timestamps
Transcript
 
[00:00:00] Misko Hevery: So the thing that I've learned from Angular.js days is make it really palatable, right. And solve a problem that nobody else has. Doing yet another framework in this state of our world would be complete suicide cause like it's just a different syntax for the same thing, right? So you need to be solving a problem that the other ones cannot solve.

[00:00:22] swyx: The following is my conversation with Misko Hevery, former creator of Angular.js, and now CTO of Builder.io and creator of the Qwik framework. I often find that people with this level of seniority and accomplishment become jaded and imagine themselves above getting their hands dirty in code.  

[00:00:39] Misko is the furthest you could possibly get, having left Google and immediately starting work on the biggest problem he sees with the state of web development today, which is that most apps or most sites don't get a hundred out of a hundred on their lighthouse scores. We talked about how Builder.io gives users far more flexibility than any other headless CMS and then we go into the two main ways that Misko wants to change web performance forever: offloading third-party scripts with PartyTown, and then creating a resumable framework with Qwik. Finally, we close off with a Ted Talk from Mishko on metabolic health. Overall I'm incredibly inspired by Misko's mission, where he wants to see a world with lighter websites and lighter bodies. 

[00:01:23] I hope you enjoy these long form conversations. I'm trying to produce with amazing developers. I don't have a name for it, and I don't know what the plan is. I just know that I really enjoy it. And the feedback has been really great. I'm still figuring out the production process and trying to balance it with my other commitments so any tips are welcome. If you liked this, share it with a friend. If you have requests for other guests, pack them on social media. I'd like to basically make this a space where passionate builders and doers can talk about their craft and where things are going. So here's the interview.  

[00:01:53] Misko Intro 
 
[00:01:53] swyx: Basically I try to start cold, 

[00:01:55] assuming that people already know who you are. Essentially you and I met at Zadar and, I've heard of you for the longest time. I've heard you on a couple of podcasts, but I haven't been in the Angular world. And now you're no longer in the Angular world.  

[00:02:11] Misko Hevery: The child has graduated out of college. It's at a time.  

[00:02:15] swyx: My favorite discovery about you actually is that you have non-stop dad jokes. Um, we were walking home from like one of the dinners and that you're just like going, oh, that's amazing. 

[00:02:27] Yes. Yeah.  

[00:02:28] Misko Hevery: Yes. Um, most people cringe. I find it that it helps break that. It does and you know, the Dad jokes, so they're completely innocent. So you don't have to worry. I also have a good collection of, uh, computer jokes that only computer programmers get.  

[00:02:47] swyx: Okay. Hit me with one.  

[00:02:48] Misko Hevery: Um, "How do you measure functions?" 

[00:02:51] swyx: How do I measure functions? And the boring answer is arity,  

[00:02:55] Misko Hevery: and that's a good one! "In Para-Meters." Uh, 

[00:03:03] swyx: yeah. So for anyone listening like our entire journey back was like that it just like the whole group just groaning. No, that's really good. Okay. Well, it's really good to connect. I'm interested in what you're doing at Builder. You left Google to be CTO of Builder. I assumed that I knew what it was, from the name, it actually is a headless CMS and we can talk about that because I used to work at Netlify and we used to be very good friends with all the headless CMSes. And then we can talk about Qwik. How's that ? 

[00:03:34] Misko Hevery: I can jump into that. Sorry. My voice is a little raspy. I just got over a regular cold, like the regular cold ceilings  

[00:03:42] swyx: conference call, right. I dunno, I, I had it for a week and I only just got over it. 

[00:03:46] Misko Hevery: It was from the conference. Maybe it wasn't from the other trip I made anyways.  

[00:03:50] Builder.io 
 
[00:03:50] Misko Hevery: So let's talk about Builder. So Builder is what we call a headless visual CMS. Uh, I did not know any of that stuff. Would've meant. So I'm going to break it down because I assume that the audience might not know either. 

[00:04:01] So CMS means it's a content management system. What it means is that non-developers, uh, like typically a marketing department think like Gap. Gap needs to update .... If you're showing stuff on the screen, you can go to Everlane. Everlane is one of our customers. Okay. And so in Everlane case, the marketing department wants to change the content all the time. 

[00:04:22] Right? They want to change the sales, what things are on the top, what product that they want to feature, et cetera. And, um, this is typically done through a content management system. And the way this is typically done is that it's like a glorified spreadsheet where the engineering department makes a content. 

[00:04:39] And then it gives essentially key value pairs to the marketing. So the marketing person can change the text, maybe the image, but if the developer didn't think that the marketing person might want to change the color or font size, then there is no hook for it, and the marketing person can't do that. 

[00:04:54] Certainly marketing person won't be able to add new columns, decide that this is better shown in three columns versus two column mode or show a button or add additional text. None of that stuff is really possible in traditional content management systems. So, this is where the visual part comes in. So Builder.io is fully visual, right? 

[00:05:13] Drag and drop. You can add it, whatever you want in the page. And the last bit is headless, meaning that it's running on the customer's infrastructure and we don't host the website. If you are, if we are hosted CMS, then it's relatively easy to make a drag and drop editor. 

[00:05:28] But because we don't host it, it's not on our infrastructure. It's actually quite a head-scratcher. And the way we do this, which I think is pretty cool, is, we have this open source technology called Mitosis, which allows us to give one input to Mitosis and it can produced any output in terms of like, whether you use Angular, React, Vue, Svelte, Solid, it doesn't matter what you use on the backend. 

[00:05:50] We will generate a component for you. And because we're generating an actual component, it drops into the customer's backend infrastructure, right. And everything just works there. Server-side rendering works. Everything that, that the customer might have on a backend, it just worked because it's a full-on regular component, whether it's Angular, React, or whatever the company might use. 

[00:06:13] So that's the unique bit that nobody knows how to do. And it's also the bit that attracted me to Builder.io and joining them. And the reason for that is because it is really easy for them to create new technology. So one of the things we're going to talk about later is this thing called Qwik. 

[00:06:30] What's super easy with Builder.io is that they can easily produce new output. So if you have a customer that already has their content, let's say on react or Angular, and they decided they want to move over to something different, like Qwik, and I will talk about why that might be a reason, it is super easy because with a push of a button, because we generate the content, we can generate the components in a different framework. 

[00:06:55] swyx: Got it. It's interesting. Have you seen Tailwind?  

[00:06:57] Misko Hevery: So Tailwind is more of a CSS framework with my understanding is correct for  

[00:07:01] swyx: building, but they had to build something for doing this essentially like having different outputs, uh, we have one central template format that outputs all these different  

[00:07:11] Misko Hevery: things. 
 
[00:07:12] So this is what Mitosis would do. Right. But Mitosis can do this across all of them, not just Vue and React, right? Every single one. Like, I don't even know what the list is, but there's a huge list of possible outputs that uh, Mitosis  

[00:07:25] swyx: can do. Yeah. You have, Liquid and JSON.  

[00:07:30] Misko Hevery: There's more, I mean, this for ones that you see over here. 

[00:07:33] Yeah. You can see pretty much everything's analyst here. We can import from Figma, given some constraints. Cause it's not a one-to-one thing kind of a thing, but we can import from Figma. So the idea is that people can design their site in Figma provided that they follow a certain set of guidelines. 

[00:07:49] We can actually import them and to turn it into HTML and then serve it up, whether it's React or whatever. One of the things is that's actually important. For example, for us is Liquid, right? Liquid is a templating system on Shopify. But it's a server side templating system and it cannot be done on the client side. 

[00:08:05] So if you pre-render on Liquid, how do you get a component to bind to it on the client? Because you would need to have the same component. Right? One of the things we can do is we can present it on a liquid and then produce an, a equivalent react component on the client and they automatically bind to it on a client. 

[00:08:21] Right. So we can do these kinds of tricks which are normally quite difficult.  

[00:08:25] swyx: So you went from building one framework to building all the frameworks.  

[00:08:29] Misko Hevery: You can think of it that way.  

[00:08:31] PartyTown 
 
[00:08:31] Misko Hevery: But my real thing, the real passion is that I want to get all sides to be 100/100. Yeah. Okay. Uh, on mobile, not on this stop, you know, a lot of people claim on desktop that they can do 100 out of a hundred mobile, that's the bar. 

[00:08:46] So I want to figure out how to do this. And in order to do that, you really have to get super, super good at rendering these things. And it turns out that if you just make a blank page and blank, white page with nothing on it, and you add a Google tag manager, that alone puts you essentially on the cusp of a hundred, out of a hundred on mobile. 

[00:09:08] So that alone, that, that act alone, right, he's kind of uses up all your time that you have for rendering. And so the question becomes like, how do we make this as fast as possible? So you can get a hundred out of a hundred on mobile. And it's very little processing time that you get to have and still get to have a hundred. 

[00:09:25] And so we do two things. One is be introducing a new framework called Qwik. little later. But the other thing we're talking about is introducing this thing called PartyTown okay. And I absolutely love PartyTown. So the person behind PartyTown is Adam Bradley, who you might know him from, making the Ionic framework.  

[00:09:43] The guy is absolutely genius. And this is a perfect example of the cleverness of it. All right? So you have, something like a Google tag manager that you want to install on your website. And that thing alone is going to eat up all of your CPU time. So you really would like to put it on a WebWorker, but the problem is you can't because the WebWorker doesn't have DOM API. 

[00:10:02] It doesn't have a URL bar. It doesn't have just about everything that the Google tag manager wants to do. Right? Google tag manager wants to insert a tracking pixel on your screen. It wants to register a listener to the, to the, uh, URL changes. It wants to set up listeners for your mouse movements, for the clicks, all kinds of stuff. 

[00:10:21] So running it on a Web Worker becomes a problem. And so the clever bit of geniuses that Adam came up with is that, well, what you really want is you want to proxy the APIs on the main thread into the web worker thread, and you can proxy them through, you know, we have these, these objects called proxies. 

[00:10:39] The problem is that the code on a Web Worker expects everything to be synchronous. And our communication channel between the main thread and the web worker thread is async. And so the question becomes like, well, how do you solve this particular problem? And it turns out there is a solution to this problem. 

[00:10:56] And the solution is that you can make a XML HTTP request, which is synchronous, on a Web worker. And then you can intercept that the request using a service worker and then service worker can talk to the main thread. Figure out what exactly did you want to do? So for example, let's say you want to set up a, uh, you want to know the bounding rectangles of some div, the Web Worker thread can make that request, encode that request inside of a XML HTTP request, which goes to the service worker. Service worker calls the main thread, the main thread figures out what the rectangle boxes, and then sends the information back to the web worker thread, which then doesn't notice anything special. As far as it's concerned, it's just executing stuff, synchronously. It's like, you're laughing, right? Because this is hilarious. 

[00:11:41] Web Workers vs Service Workers vs Atomics 
 
[00:11:41] swyx: So I'm one of those. Okay. You're, you're a little bit ahead of me now. I'm one of those people I've never used web workers or service workers. Right. Um, can we talk a little about, a little bit about the difference and like, are they supposed to be used like that? Like,  

[00:11:54] Misko Hevery: uh, so we did these two because they are supported under the most browsers. 

[00:11:59] There's a different way of making synchronous call and that is through something called Atomics, but Atomics is not available on all browsers yet.  

[00:12:07] So web worker is basically just another thread that you have in the browser. 

[00:12:12] However, that thread doesn't have access to the DOM. So all DOM APIs are kind of gone from there. So you can do a lot of CPU intensive things over there, but, , with limited abilities and this is what PartyTown solves is it proxies all of the API from the main thread into the Web Worker thread. Yeah.  

[00:12:32] Now service worker is kind of a safe thing, but the difference is that a service worker can watch HTTP requests go by and it can intercept them. And so think of it as almost like a mini web server in your browser. And so what the service worker does over here is intercepts the request that the web worker makes, because that's the only way we know how to make it blocking call. 

[00:12:56] swyx: Uh, this is the one that we use for caching and Create React App and stuff like that. 

[00:13:00] Misko Hevery: Yeah. And then, because we can make a blocking call out of a web worker, the service worker who can use the blockiness of it to make an asynchronous call to the main thread and get all the information that you need.  

[00:13:12] swyx: that's pretty smart. Is there any relation to, uh, I know that I think either Jason Miller or Surma did a worker library that was supposed to make it easier to integrate, um, are you aware of, I think  

[00:13:25] Misko Hevery: all of these worker rivalries are in heart they're asynchronous, right. And that's what prevents us from using it, right. 

[00:13:31] Because the code as written assumes full asynchronicity, and that is the bit that's. Different. Right. That's the thing that allows us to take code as is, and just execute it in a, Web Worker. And so by doing that, we can take all of these expensive APIs, whether it's, Google tag manager, Analytics, Service Hub, I think that mispronouncing it, I think, all of these libraries can now go to the main thread and they have zero impact on your Google page speed score. And we actually talked to Chrome and we said like, Hey, we can do this. Do you think this is cheating? Right? Like, do you think that somehow we're just gaming the system and the message was no, no, because this actually makes the experience better for the user, right? 

[00:14:17] Like the user will come to the website. And because now the main thread is the thing that is running faster and none of this stuff is blocking. You actually have a better experience for the user. The other thing we can do is we can actually throttle how fast the Web Worker will run because when the Web Worker makes a request back to the main thread to say, like, I want the bounding box, or I'm going to set up a tracking pixel or anything like that, we don't have to process it immediately. 

[00:14:43] We can just say, well, process this at the next idle time. And so the end result is that you get a really high priority for the main thread and then the analytics loads when there's nothing else to do. Which is exactly what you want, right? You want these secondary things to load at a low priority and only be done when there's nothing else to do on the main thread. 

[00:15:02] PartyTown Demo 
 
[00:15:02] swyx: That's amazing. Okay. All right. We have some demos here if we want to  

[00:15:05] Misko Hevery: So if you, let's pick out the simple one, the element, right. And what you see in the console log is this is just a simple test, which performs, uh, synchronous operations. But what you see on the console log is that all of these operations are intercepted by the service worker. 

[00:15:22] Right. And we can see what particular API on the web worker is trying to do and what the result is, what the return code is, you know, how do we respond and so on and so forth. And so through this,you can kind of observe what your third party code does. By the way. The nice thing about this is also that, because you can observe, you can see is ECP. 

[00:15:43] If you're a third-party code, because we essentially trust them, right. Fully trust this third party code on your website and who knows what this third party code is doing. Right? So with this, you can see it and you can sandbox it and you can, for example, say like, yeah, I know you're trying to read the cookie, but I'm not going to let you, I'm just going to return an empty cookie because I don't think it's your business to do that. 

[00:16:04] You know, or any of those things we can do. So you can create a security sandbox around your third party code. That is kind of, as of right now is just implicitly trusted and you can, you have a better control over it.  

[00:16:18] swyx: I could filter for it, I'm basically, I need HTTP calls and then I need any cookies. 

[00:16:23] Right. So,  

[00:16:25] Misko Hevery: yeah. So in this case, there will be nothing because this is just showing off element API, but I think you go to previous page  

[00:16:33] swyx: Before we go there. is there anything significant and? It says startup 254 milliseconds?  

[00:16:38] Misko Hevery: Yeah. So the thing to understand is that it is slower, right? We are making the Google tag manager slower to start up. 

[00:16:46] Right. So it's definitely not going to be as fast as if it was on a main thread, but it's a, trade-off, we're doing intention. To say like, Hey, we want to give the CPU time to a user so that the user has a better experience rather than eagerly try to load analytics at the very, very beginning and then ruining it for the user. 

[00:17:04] So while in theory, you could run a react application and the web worker, I wouldn't be recommended because it will be running significantly slower. Okay. Um, because you know, all of these HTP requests, all these calls across the boundary, uh, would slow down. So it is a trade-off.  

[00:17:23] swyx: So this is really for the kind of people who are working on, sites that are, have a lot of third-party scripts for,  

[00:17:30] Misko Hevery: well, all the sides have third party scripts, right? 

[00:17:32] Like any kind of a site will have some kind of third-party whether it's analytics ads or just something that keeps track of what kind of exceptions happen on the client and send them back to the server, right. Standard standard things that people have on a website. And instead of the standard things that are making, preventing you from getting a hundred out of a hundred on your score. 

[00:17:52] Right. Okay, amazing. So this is a way of unloading stuff from the main thread Got  

[00:17:58] swyx: What's the API? I haven't seen the actual code that, Party Town. Okay. There's a, there's a adapter thingy and then  

[00:18:05] Misko Hevery: you stick it. So we, those are just for react components. There is also vanilla. Just go a little over. 

[00:18:14] So do  
 
[00:18:16] swyx: you see how we have to prioritize, React above Vanilla? 

[00:18:20] Misko Hevery: Even lower? This just shows you how you get the PartyTown going. Oh, here we go. Text to pay. We go right there. 

[00:18:25] You're looking at it right there. So notice what. We asked you to take your third party script, which, you know, if you go to Google on an exit, it tells you like, oh, take this script tag and just drop it inside of your head. Right. Or something like that. So what we do is we say like, do the same exact thing, except change the type to text/partytown. 

[00:18:43] And that basically tells the browser don't execute it. Instead, PartyTown will come later, read the stuff, ship it over to the web worker and then do it over there.  

[00:18:54] swyx: So the only API is you, you just change this, that's it? Yes. Yes.  

[00:18:58] Misko Hevery: So you drop a party down script into, uh, into, which is about six kilobytes. And then you go to all of the third-party places and just add, type text/partytown, and that ships them off to the other place. 

[00:19:10] swyx: So, um, it feels like Chrome should just build this in like script, script type third party. Right. And then just do it.  

[00:19:20] Misko Hevery: Yeah. I mean, we're having chats with them. You never know. Maybe if this shows up to be very useful technique. It might be something that Chrome could consider. Well, certainly we need a better way of making synchronous calls from the web worker thread to the main thread, not from the main ones of the web, right. 

[00:19:37] That's clearly a bad idea, but from the web worker, the main, it would be really nice to have a proper way of doing synchronous calls.  

[00:19:44] Atomics 
 
[00:19:44] Misko Hevery: Atomics might be the answer. And so it might be just as simple as getting all the browsers to adopt Atomics because the standard already exists.  

[00:19:51] swyx: And I see what, what is this thing I've never heard of it? 

[00:19:55] Misko Hevery: Atomics is basically a shared memory array buffer between two threads and you can do, atomic operations like locking and incrementing and things of that sort on it. And they can be done in a blocking way. So you can, for example, say, increment this to one and wait until whatever result is three or something like that. 

[00:20:14] So then you're giving a chance for the other thread to do its work. I  

[00:20:18] swyx: mean, this is like, so I'm writing assembly, like,  

[00:20:22] Misko Hevery: It's not assembly it's more, you know, semaphore synchronization.  

[00:20:26] swyx: Um, okay. Yeah. I see the, I see the locks and stuff, but this is, I can't just like throw in a third party script here. 

[00:20:33] Misko Hevery: No, no, no. This is something that the PartyTown would use to get synchronous messaging across. Right. Because currently it is kind of a hack that we create an XML HTTP request that is blocking that stuff with a service worker. Like this is craziness, right. So Atomics would definitely be a nicer way to do this. 

[00:20:51] swyx: I think the goal is definitely very worthwhile that the underlying, how you do it is a bit ugly, but who cares?  

[00:20:57] Misko Hevery: Yeah. So the goal is very simple, right? The goal is, for us, we think we can have the best CMS, if we can produce websites that are a hundred out of a hundred on mobile, right? 

[00:21:07] That's the goal. And if you look at the current state of the world, and if you go to e-commerce websites, it's pretty dismal. Like everybody gets like 20 something on their scores for their sites, right? Even Amazon that has all the resources to spend, will only get 60 out of a hundred on their score. 

[00:21:24] Even Google website themselves gets it only about 70, out of a hundred. Right? So the state of the world is not very good. And I feel like we are in this cold war in a sense that like everybody's website is equally bad, so nobody cares. Right. But I'm hoping that if you can build a couple of websites that are just amazingly fast, then the world's going to be like, well, now I have to care. 

[00:21:46] Qwik and Resumable vs Replayable Frameworks 
 
[00:21:46] Misko Hevery: Right? Because now it is different. And so now we're getting into the discussion of Qwik. So what is clicking and why do we need this? So, um, the basic idea behind Qwik, or rather than, let me back up a second of why existing websites are slow.  

[00:22:04] And so there's two reasons, right? One is third party scripts, and we just discussed how we can solve this through PartyTown right? I mean, we can move all of their party scripts off.  

[00:22:12] However, even if you move all the third party scripts off, your problem is still going to be that, uh, the startup time of your website is going to be pretty slow. And the reason for that is because all websites ship everything twice. First it's a server side rendered HTML, right. 

[00:22:30] And the page comes up quickly and then it's static. So we need to register listeners. Well, how do we adjust your listeners? Well, we download the whole site again, this time they came to in a form of TypeScript or JavaScript, and then we execute the whole site again, which is by the way, the server just did that. 

[00:22:49] Right? Yup. Yup. And then we know where to put up listeners and, that causes, you know, this is a perfect graphic for it, right. That causes double loading of everything. So we, we download everything once as HTML and then we load everything again, as JavaScript and then the execute the whole thing again. 

[00:23:07] So really we're doing everything twice. So what I'm saying is that the current set of framework are replayable, meaning that in order for them to have the bootstrap on the client, they have to replay everything that the server, literally just did, not even a second ago. And so Qwik is different in a sense, because it is resumable. 

[00:23:27] The big difference with Qwik is that the Qwik can send HTML across, and that's all. That's all it needs to send across. There's a little tiny bootstrapper, which is about one kilobyte and about one millisecond run, which just sets up a global listener and alert for the system. And no other code needs to be downloaded and it can resume exactly where the server left off. 

[00:23:48] So you need to have some formal way of serializing, the state, getting the state to the client, having a way of deserializing the state. More importantly, there's an importance to be able to render components independently from each other, right? And this is a problem with a lot of frameworks, which is - even if you could delay the startup time of a, uh, of an application, the moment you click on something react has to rerender the whole world right now, not rerender, that might be the wrong term, but it has to re execute its diffing algorithm from the root, right. It has to build up the vDOM. It has to reconcile the vDOM, has to do all these things, starting at the root. 

[00:24:26] There's no real way to not make it from the root. And so that means that it has to download all the code. And so the big thing about Qwik is, how can we have individual components be woken up individually from each other in any order? Right? I mean, people tend to talk about this in form of micro components or microservices on the client, right? 

[00:24:46] This is what we want, but at like the ultimate scale, where every component can act independently from everybody else.  

[00:24:54] swyx: Yeah. Yeah. I think, we should talk a little bit about that because basically every single component is its own module and separately downloaded. So you're really using the multiplexing or whatever you call it of HTTP/2, right? 

[00:25:05] Like you can parallelize all those downloading. Right. The main joke I made, because I saw this opportunity and I was like, immediately, like, I know this will be the most controversial part, which is essentially. Uh, the way you serialize is you put everything in HTML, right? Like, like that. 

[00:25:23] So, so I, I immediately feel that, and it will stir up some controversy, but like also, like, I think the, the interesting, I mean, we should talk a bit about this. Like, obviously this is not handwritten by, by, by people. So people should not be that worried. Um, but also like there are some legitimate concerns, right. 

[00:25:40] Qwik vs React - the curse of Closures 
 
[00:25:40] swyx: About how I think basically Dan Abramov was, was also the, the, you, you responded to Dan. Um, so Dan said something like this, okay. So it wasn't a direct response to Qwik but Qwik serializes all state in HTML, and that's something that we considered for React Suspense. And he says, basically the question was, have you considered allowing server components to have serializable state using equivalent? 

[00:26:03] it's been proposed somewhere earlier. This doesn't work generally state is in reaction arbitrary. Payloads would get huge essentially, like, "does it scale?" Is the question. Uh, and he said that this was done before and I went and looked it up and he was like, yeah. And it's actually what we used to do for ASP .NET WebForms. Right.  

[00:26:18] Misko Hevery: So if you will look at react the way to React does things. And so I want to pull this up on one of the dev, uh, dogs. I actually talk about it and it might be useful to kind of pull it out. Yeah, the one you are on right now, the answer adoptable fine-grained lazy loaded. The point is that if you have a react component, react components take heavily, closures, right? Closure is the bread and butter of react components and they rely on closures everywhere and it's beautiful. I it's absolutely nice. I really like the mental model. However, it doesn't serialize, right? 

[00:26:50] You can't take a closure and serialize it into HTML. So what Qwik is trying to do is it's trying to break this up into individual functions. Clearly functions cannot be serialized, but functions can get a URL , a globally known URL, uh, which can load this. So if you scroll a little lower, you will see a, uh, Qwik component , and the difference is, in a Qwik component, we'll have these declaration template, which is which points to a location to where this particular thing can be loaded, if you scroll even further, it talks about how this particular thing can be served up in pieces to the client, if you do this thing. Right. So while it's maybe true that like, oh, it's been tried before and we didn't do it right. 

[00:27:32] Qwik Demo 
 
[00:27:32] Misko Hevery: Have people really tried to solve every single one of these problems. Right. And there's a huge myriad of them that Qwik is trying to solve and kind of get over. And so maybe I can show it to you as a demo of what I kind of have a to-do app working. So let's let me, let's talk about this. 

[00:27:50] One of the things. So by the way, the screenshot you have on your Twitter account, that is the old version of Qwik, I've been chatting with you and bunch of other people at the conference, I really got inspired by lots of cool things. And this is a kind of a new version I'm working on, which has many of the issues fixed up and improved. So the thing I'm going to show you is standard todo example, right? I mean, you've seen this millions of times before. 

[00:28:15] swyx: By the way. I did not know that, uh, I think Addy Osmani made this original to do yes, he did. He did. And it's like the classic example. That was a classic example,  

[00:28:24] Misko Hevery: right? 
 
[00:28:27] So remember the goal for us is to serialize everything and send to the client in a form that the client can resume where the silver left off. Right. And then everything can be downloaded in pieces. So there's a lot of things to talk about. So let's start with, with how this works first, and then we can talk about how different pieces actually fit together. 

[00:28:46] So, you know, first thing you need to do, is, standard, define your interface for an item and define your interface for Todos, which is the collection of items, which contains , number of items completed in the current filter state, and just a list of items like so far, nothing. 

[00:29:02] Now the special thing comes in that when you declaring a object that you want to serialize, you will run it through this special function called Q object. And it's a marker function and does a couple of things to an object. But you're just basically passing all the stuff in and notice the individual items on Q objects as well. 

[00:29:20] The reason I did it this way is because I want to serialize individual line items separately, because I know that I'm going to be passing the individual items into separate components individually. Right? So what this basically says to the system is like, there is a top level object. Which is this guy right here and it can have rich state, but remember it has to be JSON serializable. 

[00:29:43] Therefore it cannot have cyclical things inside of it. It has to be a tree, but inside of it, it can have other objects and those can form cyclical things. So using the combination of those two, you can actually get cyclical graphs going inside of your application. But individually, each Q objects doesn't have that. 

[00:30:02] So that's a bit of a magic. If I scroll over to the actual running application, what you will notice is these Q objects get serialized like right here. So for example, this one has some ID and you notice it says completed zero and the inside of it has individual items. And notice these items are actually IDs to other locations. 

[00:30:22] So this ID ending in Zab is actually pointing to this object right here, which has other things. So the whole thing gets serialized. And unlike the demo I showed in Zadar, I have moved all the serialized content at the end, because I don't want to slow down the rendering of the top part. And so if you go, let's go back to our application. 

[00:30:41] So if you have Todo app, the Todo app is declared in a slightly more verbose way than the way the one would be declared in React. But if we do it this way, then we can serialize the closures, right? The closures don't have the issue with non serialized. By the way, the regular React way of doing things still works here and you can do that is just, they become permanently bound to their parents. 

[00:31:05] They cannot be lazy loaded. So you can think of it as having two mental models here. You can have lightweight components, which are essentially the same as react components, or you could have Q components, which are slightly more heavyweight, but they get the benefit of having the whole thing, be composable and get lazy a little bit so on and so forth. 

[00:31:24] So in this particular case, we're saying that there is a Todo app component and the QRL is this magical marker function that tells the system that this content here needs to be lazy. Or rather let me phrase it differently, it says the content here can be lazy loaded. The beauty of Qwik is that it allows you to put a lazy load of boundaries all throughout the system. 

[00:31:48] And then an optimization phase later decides whether or not we should take advantage of these lazy loaded motor boundaries, right in normal world, the developer has to put dynamic imports and that imports that asynchronous and a pain in the butt to work with, it's not simple. Right? So instead, what Qwik wants to do is say like, no, let's put dynamic imports everywhere, but do it in a way where the developer doesn't have to worry about it and then let the tooling figure out later whether or not we should actually have a dynamic import at this location or not. 

[00:32:18] Yeah. So even though this file, this there's two applications is in a single file in the tooling. We'll be able to break this file up into lots of small files and then decide in which order the things should be shipped to the client in order to get the best experience. You know, if there's a piece of code that never runs in the client will then put it at the bottom of the, of the chunks, right? 

[00:32:38] If there's a piece of code that is going to be most likely, you're going to click on it and put it up to the top. So, anyway, so that's kind of a diatribe here with a little bit of an off the rails here, but what this produces is a to-do and it turns the code, right? This QRL function, it says on render, it gets turned into a URL. 

[00:32:58] And this is what allows the build system to rearrange the code. And so this URL basically says, if you determine that Todo needs to be re re rendered, uh, then you can go download this piece of code. And that will tell you how do we render the Todo, right.  

[00:33:14] You know, you're using a header and we're using main, notice we're binding Todos in there. So it looks like a regular binding, but the system has to do more work. So in this particular case, the main has to see if it has Todos, it has to refer to a object. So notice this, this ID here matches the ID here. And this is basically how the system knows that this component here, because if you look over here, the main and foot are, both of them want to know that you do this right? 

[00:33:42] So both of these components need to have the same object. And so, yeah, exactly. So this main here, as well as the footer, they both have a same ID passed in here. And that's how the system knows like, all right, if I wake you up, I have to make sure to provide you with the same exact ID. Now, not only that there is also this particular thing, which is just a copy of it, but, but in this particular. 

[00:34:08] What it does is, is the list, all of the objects that could potentially affect the state of this component. And when you go and you modify one of these, state objects, the state, these objects actually keep track of each other and they know which components need to be woken up and affected. So I think there's an example of it somewhere here later, uh, like right here, right in here, it says, Hey, if you, uh, you know, do a key up on the input right here, if I type here over here, something, then the key up runs and then eat, enter runs, you know, add a new item, which is just the function that the function right here, which just pushes an item and new item into the list. 

[00:34:54] And it sets my current state to text me. And so the system knows that in this political case, in a header, this input right here, Has its own state right here. So let me refresh this again. Um, this header has its own state one eight, whatever, right? Which if you look over here is right here. It's text blank, right? 

[00:35:16] So we find typing here. I'm going to change the state over here. And then if I set the state to blank, then the system knows, oh, that's object 1 8, 7 1, or whatever. I can run a query. I can run document DOM, querySelectorAll. And I can say, give me, uh, all the queue objects, remember how the selector for this start something like this. 

[00:35:44] Anyways, there's a way to run a selector that will allow me to whatever, whatever the code is, right? I'll run the selector and this selector will then return this header back to me saying this is the object or rather, this is the component that is, has interests registered into this object, which means. 

[00:36:04] Because I've selected this thing. I have to find the Q render message and send the Q render message to download its template and we render the object. And so what this allows you to do is have a completely distributed set of components that can be awoken only when a relative, you know, appropriate data is changed rather than having this world of like, well, the state has changed and I don't know who has a reference to what? 

[00:36:30] So the only thing I can do is we learn that the whole page. Well, that's kind of a, it doesn't help you, right? Cause if you run the, the whole page, then there's the whole, the code has to come in here. Right. So that's not helpful. We want to make sure that we only download the code is actually needed. And so you need to have some mechanism by which, you know, like if I change this piece of code, if I change this object, which component needs to be awoken, right. 

[00:36:54] And normally like if you have Svelte, Svelte does through subscription, this particular trick, the problem is subscriptions cannot be serialized into the DOM. And so we need a mechanism where the subscription information is actually DOM serializable, right? And this is what the Q object is, or the subscriptions that the individual components have to undo to other things. 

[00:37:18] And so the other thing I kinda want to point out is that we can then bind a complex object. Like in this case, it's a complicated state that'd be assigned to reduce yet. It turned into a binding that's serializable into the bottom, right? So if I go back here, see I'm jumping around. So we have our footer. 

[00:37:38] If we have our main, the main is declared over here, you know, standard, uh, JSX in here where you, you want to iterate over a bunch of items. There's a host. Okay. So one of the things we need to do is, um, in react, when you have a component, the component is essentially hostless, or I would say it's life component in the sense that it doesn't have a parent, right. 

[00:38:02] Uh, and that is wonderful in many, many situations, but sometimes it isn't. The problem we have is that we need to have a component. We need to have a DOM element for each component that can be queried using querySelectorAll so that we can determine if there is a listener on it, or if there is a subscription on a particular object or a single back. 

[00:38:24] So we have this concept of a host element, and this is one way in which the Qwik Q component is more heavyweight than the react component. You can still use react components if you want, you just don't get the benefits we talked about. And, and so a host element is, is a way of referring to the, the host element and adding an attribute to it. 

[00:38:47] Right. And saying like, oh, I want the host, I'm going to have a classmate. And so if you go into, let's see Maine, uh, right. So it's supposed to be a classmate, right. So it's the component that, that adamant. So normally, uh, the way you do this normally in react is that the main would be a object that the JSX of the re. 

[00:39:07] The child react component, right? In this particular case for a variety of reasons, we need to eagerly create this particular thing. So then it's a placeholder for other things to go in. And so we need to do an eagerly and then we need a way of like referring to it. So that's what host is, sorry for the, uh, diatribe anyways, but this is how you create your items, right? 

[00:39:31] And notice the way you got your items is you just got it from your prompts and you can iterate over them. Right? You can reiterate and run the map and produce individual items. And for each item you will pass. And the key. So if you look at the item here, it's prompt says like, I am going to get an item in here. 

[00:39:50] And my internal state is whether an I am not, I am an editable state. So these are you, basically your props. And this is the components state in here. And, uh, you know, on mound, we create a component states that we're not, we're not an editable state. And then when the rendering runs, uh, it has both the information about the item as well as about whether or not you are currently editing. 

[00:40:13] Uh, and if you look at the UL, so here's our, one of our items that got generated, notice that the item that passed in as a ID here, right? So if you go to the script at the bottom and see this one ends in PT six, so we should be able to find, here we go, this is what actually is being passed in to that particular component. 

[00:40:34] But notice there's a second object. Not only is there a, um, a PT six objects, there's also the secondary option. That's the state of the components. So if the state of the component, we're basically saying here is like, if this object changes or this object changes, I want to know about it and I need to be. 

[00:40:52] So these objects form a graph, right? The presents, the state of your system. And then the Qwik provides a mechanism to serialize all this information into the DOM in such a way that we know which component is to be woken at what time. So if I start typing in one of the things you're going to see is that on the first interaction, this script that will disappear, because what actually happens is that when you interact with the system, it says like "I need to rehydrate myself". Right? And so it goes to the script tag and, uh, reads it. Let me give it back over here, read it leads to the script tag and figures out. You know, these utilizes all these objects because takes this object, puts them inside of this object to build up the graph and then goes back into the DOM tree and say like, okay, so I need to put this one over here. 

[00:41:40] I need to put this one over here, this one over here and so on and so forth and puts all these objects back. What are they supposed to be? And now you are, your state is back in a, in these components, but the components aren't present yet. They're not awoken, right? Because none of their, uh, Mount or their render functions actually got called. 

[00:41:59] And because the functions didn't get called, uh, the code didn't have to get downloaded. So everything is super lazy. Right. So when I go and I hit a key over here, the state gets de-centralized, but the only piece of code that gets downloaded is right. It is, it is right. This thing right here. 

[00:42:18] Nothing else.  

[00:42:19] swyx: Can we show that the network actually, ah,  

[00:42:22] Misko Hevery: I would love to, but that part is mocked out right now in the old demo, in the demo that I have, that I did for the conference, that one actually had it properly working. But the feedback was that the D as a developer, there was a lot of things I had to do. 

[00:42:40] Qwik Compiler Optimizations 
 
[00:42:40] Misko Hevery: And so I wanted to simplify it. So one of the things I did is I figured out a way, or rather I spoke with Adam, uh, the same Adam that did PartyTown. And we figured out how to make it, make the tooling smarter so that the developer doesn't have to do this. So what actually happens is that when you have the QRO over here, what actually happens is you, the, the code automatically gets refactored. 

[00:43:06] And you will get a new function with factor like this. The system will put an expert on it. And what gets placed in this location is a string that says something like, you know, ABC. Uh, hash you local, right. Or something like that. Right? So by doing this transformation and that piece of code is not working in this transformation, um, the, uh, the system can then, uh, lazy load, just the spirit physical code, nothing else. 

[00:43:39] But in order to do this transformation, we have to make sure that this code here doesn't have any closures. Right? I cannot, it cannot close over something and keep that variable because if it does the whole thing doesn't work. And so the nice thing is that we can still write it in a natural form, but one of the constraints here here is that you can't close over any variables. 

[00:44:01] Now there's no variables to close over them. The system is designed in such a way that it doesn't need it. Instead of things like props and state are explicitly passed into you, as well as to the thing of the child, whether they're halo as well. So you don't have a needs to create these kinds of closures, but it is a constraint. 

[00:44:19] And this is what allows the optimizer to go in and rearrange your code base in a way where we can then determine what things are used. So, so in this particular case, we can, for example, determined that you're likely to go and interact with the input box, but you are very unlikely to actually call this on render, because this is the kind of the Chrome, the shell of the application, and wants to show them the applications loaded you will never, ever interacted. 

[00:44:46] Right? So what you can do is you can take all these imports and you can sort them not alphabetically. You can sort them by the probability of usage. And then once you haven't sorted by the probability of usage, you can tell the optimizer like, okay, take the first N ones so that I have a chunk that's about 20 kilobytes because we think 20 kilobyte chunks. 

[00:45:08] And then the system can be like, okay, let me add a whole bunch of them until I have 20 kilobytes. Let me add a nice chunk, then underline about 20 clubs. And I kind of do these chunking all the way on the end. And then the last chunk we'll probably end up with a bunch of stuff that never ever gets loaded. 

[00:45:22] Right. But the problem is the current way we design applications. You can't do that. You just can't right. And so we have this mentality of like, we have frameworks that have amazing developer experience, but they set up the overall experience down the path of monolithic code base and any kind of, um, lazy loading that the Builder can add after the fact. 

[00:45:50] It's just like kind of a kloogey workaround. Right? And that's the thing that the Qwik solves it says like, no, no, no, let me help you design an application that has still nice developer experience, but let me structure things in a way so that I can later rearrange things, right? Let me keep you on this guide rails of like, make sure you do it in these ways. 

[00:46:12] And so everything is in the quickest set up in a way where it keeps you in this guide rails. And the result is, is a piece of code that the optimizer, then the Qwik can rearrange, right? It can go and pull out this function. It can pull out this function. It can pull out all of these functions and turn them into a top level functions that are exportable. 

[00:46:31] And it can then, um, tree shake the stuff that's not needed and produce chunks that can then be lazy loaded into your application.  

[00:46:41] swyx: Like four or five years ago, I think there was some, uh, I think even at the Chrome dev summit or something like that, there was a effort to use Guess.js to basically use Google analytics, to optimize all this, intelligent pre-loading or loading predictions. 

[00:46:58] Um, is that how I think I missed the part about how, like, how you pull in the statistics for, for optimizing.  

[00:47:05] Misko Hevery: So the first thing to talk about, I think is important to understand is that unless you can take your application and break it up into lots and lots and lots of chunks, I do that. Yeah. There's nothing to talk about. 

[00:47:15] Right? If your application is one big chunk, there's nothing to talk about. You would have to load the chunk end of discussion.  

[00:47:21] swyx: Well, so the chunk goes page level, and now you're doing component level, right? So they were, they were saying we split it by page and we can predict the next page. So,  

[00:47:30] Misko Hevery: so look at Amazon, right? 

[00:47:34] Most of this stuff, you will, I mean, you can click on stuff and there's a menu system up here and let's pick a random component here. How do I, let me just go to something. Oh, come on. Just give me a detail view of something every day. Uh, you know, most things here never have to be rendered. Like, for example, there's a component here. 

[00:47:52] This component never, ever changes. Nothing here. We're render nothing. We'll run it there, here. Uh, yes, these are components and I can click on them and they update the UI over here. But if I'm interacting here, why am I downloading the menu system? Right. And so the point is, if you have a page like this, there is huge number of components in here, but most of them either never update, or in my current path of interaction, I just don't need to update them. Right. If I'm using the menu system, then I don't need to download this thing here. And if I'm interacting with my item then I don't need the menu system, and I'm not, unless they put something out to car, do I have to worry about my shopping cart? 

[00:48:33] Right? And, and this is the problem is that we currently bundle the whole thing up as one giant monolithic chunk. And yes, there are ways to break this out, but they are not easy. And everybody knows how to do route level break up. But like even on rough level, it's, it's not, it's not fine grain enough. 

[00:48:53] Right. And so the magic of Qwik is the magic of writing the code in this particular style. Is that for a typical size application, I can break up the application in literally thousands of chunks. Now that's too much. We've gone way too far. I do. These, these chunks are too small and we don't want that. 

[00:49:13] Right. But when I can break things up, it's easy for me to assemble bigger chunks out of it. But the opposite isn't true, right? If I have a big chunk and I want to break it, well, good luck. You know, no amount of tooling is going to do this. As a matter of fact, the best AI system we have, which is right here in our brains. 

[00:49:31] Right. Even if you give it to the developer and say, go break this thing up, it's a head-scratcher that takes like weeks of work. Right? And so we are in this upside down world of like build a humongous thing and then have this attitude of like, somehow tooling will solve it. Tooling can solve this problem. 

[00:49:52] Right. You have to do it the other way around. You have to design a system which breaks into thousands of little chunks. And then the tooling can say, yeah, but that's too much. It's too fine-grained. And let me glue things together and put them together into bigger chunks because. Through experience. We know that an optimal chunk size is about 20 kilobytes, right? 

[00:50:11] And so now the thing you want is to get a list, the order of which the chunks are used, and that's easy, right? If you're running your application, you can just keep statistics on what, how users interact with your application and that's that the sticks can be sent back to the server. And so once you can get back on a server is just a ordered list of the probability by which you're going to need individual chunks. 

[00:50:35] And that sort of lists that sorted list is all you need to tell the optimizer, like start at the top of the list, keep adding items until you get to a correct chunk size, they'll start a new job, right. And you keep doing this over and over. Okay. Now the reason I get excited about this, the reason I talk about it is because we completely ignored this problem. 

[00:50:57] Right. We, we have these amazing frameworks, whether it's Angular, React, Svelte or whatever that allow you to build these amazing sites. But on the end of the day, we all have horrible page speed scores, because we're not thinking about it from the correct way. And the attitude for the longest time has been, the tooling will solve it later. 

[00:51:18] And my argument here is no, the tooling will not solve it later. If you make a mess of this code base, there's nothing that tooling can do. Yeah.  

[00:51:27] swyx: Um, there's so many directions. I could take that in. So first of all, uh, the React term for this is a sufficiently smart compiler, which has been in the docs for like four or five years. 

[00:51:36] Yeah. That's an exhibit,  

[00:51:39] Misko Hevery: but that's my point. Like you cannot make a sufficiently smart compiler 

[00:51:43] swyx: so is, I mean, is there a compile step for this because of the QRL section.  

[00:51:47] Misko Hevery: So right now it's actually running without compilation whatsoever. So one of the things I want to make sure that it runs both in a compiled and uncompiled state, and that's why it comes up with these bogus things like mock modules, et cetera. 

[00:52:01] Uh, and I think if you go to the network stab, it loads the mock module, and it just re-exports it. I can't really show you, but basically all of these things are kind of just in there. So currently this thing runs as a single monolithic application, but the, the way this thing would work is that as I pointed out everything, every place that you see QRL is a hint to the compiler to go and extract this. 

[00:52:26] The compiler, literally, we would just think. Ctrl+Shift+R extract here and then gives it a name which will be a header pull on a key up. Right. And then it repeats the same exact thing over here. So Ctrl+Shift+R extract. This is a header onMount. I mistyped it. It's okay. I get it right. And the same thing here, controls have to go Ctrl+Shift+R 

[00:53:00] Qwik Questions 
 
[00:53:00] swyx: what if I need to do like conditional loading because the competitor doesn't know which branch I need to go down.  

[00:53:09] Misko Hevery: So I'll answer the question in a second, did you want to point out, so notice what ends up here? The header is super, super lightweight. There's nothing in here. Cause these things, these two things will get converted into these URLs, right? Yeah. And because of that, this header is permanently bound to the onRender of the to-do app. 

[00:53:28] Right? If you load a to-do app you're also loading the header and of Main and a footer, but the thing we've done over here is we made this super lightweight, and this is what allows the lazy loading to happen.  

[00:53:41] Now you're asking what about other components? Uh, easy. I mean, uh, if you want it to conditionally include the header, you know, standard stuff. 

[00:53:51] Uh, true. Right now the, the header itself will always be permanently bound into the, on render of the to-do app. Right. However, because we did the trick when we extracted everything out of it had already super, super lightweight. It doesn't contain anything. Right? So the only thing the header really contains if you go in here is the what to do on this URL was the only thing that's in there and also this vendor, right? 

[00:54:18] So these two URLs are the only thing that is contained inside of the header by itself. Okay. It's only when we decide to render the header, do we go into the header? And we say, okay, we're doing a rendering. So what's your URL. And we look at this URL right here, we download the code. And so now the rendering pipeline has to be a synchronous. 

[00:54:38] We download the code and then we go and execute the content. And we basically fill in the content the better now in the process, we also realize, oh, we also have to download this piece of code. And this is where statistics would come together. And we basically tell us that this URL and this URL always get downloaded together. 

[00:54:57] And therefore the optimizer will be smart enough to always put them together in the same file in the same chunk. And, uh, you know, we rented the content. Got it.  

[00:55:09] swyx: Okay. So, uh, one small piece of, uh, API feedback slash questions. Uh, yeah, you have, the tag name is optional there. I guess that's a hint to what to store, right. 

[00:55:18] Misko Hevery: So right now it says to-do right here. If I have a  

[00:55:22] swyx: out,  
 
[00:55:24] Misko Hevery: it becomes, uh, just the div. Um, so the system doesn't care. What the thing is, it means eight element. Um, it could be any element they will do just fine. It's easier to kind of on the eyes if it actually says to do right. So that's the only reason for okay. 

[00:55:42] Got it.  

[00:55:43] swyx: the bigger piece is okay. It's like a lot of HTTP requests. Every time I basically, like every time I make a request, every time I interact with the app, I essentially need to do a whole new handshake, a whole new network transfer. There's some baseline weight for that. 

[00:56:00] Right. Chunking links that helps, um, is there a preload essentially? Is there a less programmatically say like, okay. And by the way, uh, this is important for offline capable apps. So I like, let's say like, I'm going offline. Like it's five things. I know I don't need it right now, but like as an app developer and  

[00:56:18] Misko Hevery: I know. 
 
[00:56:19] Yes. So, uh, we can totally do that. Um, we, uh, there is a level worker that will be set up and the web worker will get a list of all the chunks in the woodwork who will try to go and download them and set up the caching for you, uh, in these chunks of time. So that Y when you interact, the only thing that the browser has to do is execute the code now, because these chunks are small, the execution code, if we don't, we're not worried about it, right. 

[00:56:46] In the case of like on typical framework, that's replaceable. The problem is that the first time you interact with this thing, you have this huge amount of code to download parts and execute. But this isn't the case here because every interaction really only brings in the code that's strictly necessary for this interaction. 

[00:57:04] So again, we go to like Amazon, right? If I hover over here over these things, and it changes the image on the right side, the only code that gets downloaded and executed is the code for this. Now it's already pre downloaded because their web worker would go and pre fetch it for you. So the only thing that the browser has to do is parse the code and execute the code for the on hover, a callback that goes and updates this components URL. 

[00:57:27] Right. That's it? No other code needs to be downloaded in a presence. Yep.  

[00:57:31] swyx: Got it. anything else that we should cover real Qwik?  

[00:57:35] Misko Hevery: I feel like I have talked your ear off and you have been such a good and gracious host. Uh, happy to answer questions. I don't want to overwhelm people, but I am super excited as you can talk. 

[00:57:46] I'm super excited about this. I think it's a fundamental shift about how you think about a framework. So like, if you look at all the existing frameworks, they're all arguing about, like, I have a better index, I can do this better or that better and et cetera. Right. But fundamentally they're not the same, like essentially the same buckets they can all do about the same thing Qwik. 

[00:58:05] I think it's a whole new ballgame because the Qwik thing is not about like, oh, I can render a component just like, you know, 50 other frameworks can do as well. The thing that Qwik has is I can do it. I can give you microservices for free. I can give you this micro component architecture for free and I can produce a bundling. I am the sufficiently advanced compiler. Okay. Let's put it this way. This thing that you thought you could have and solve for you, doesn't exist unless you have the current guidelines. Right? So the thing with Qwik is that it is the thing that allows you to have a sufficiently smart compiler to give you this amazing times to interactivity, right? 

[00:58:48] At the end of the day, is the, there's nothing faster than downloading HTML for your website. I mean, that's the cake, right? Yep. So the reason why Qwik is fast is not because Qwik is clever in the way it runs JavaScript or anything like that. So no Qwik as fast because they don't have to do anything. 

[00:59:04] Right. When you, when you come to a Qwik website, there is literally nothing to do, right. We're fast because we don't do anything. And that's  

[00:59:13] swyx: your baseline is like a one kilobyte bike loader, right?  

[00:59:16] Misko Hevery: One come on loader with all the loader, does it sets up a global list? Right. So let me, let me go back. Sorry, let me share one more thing. 

[00:59:22] So here's your input, right? So if you go to a header, here's the input, right? The reason we know how to do something on it is because we serialize this thing called on:keyup, and there is a URL, right? So when this thing is first executed, nothing is done. Like this content shows up and it said we're done. 

[00:59:41] And the only reason why we know to do something next is because when I do a key up here, the event, bubbles up all the way to the root, that route, we have this Qwik loader, which registers, uh, the code base, uh, and figures out what to download and what to do next. Right? That's the only reason why the whole thing works. 

[01:00:05] Qwik vs Islands Architecture 
 
[01:00:05] swyx: That's amazing. Um, I want to get your commentary on a couple more things that are related to this, which is first of all, the islands architecture, um, w also by Jason Miller, um, have you come across, it, talked to him about it, how Qwikly  

[01:00:19] Misko Hevery: I, uh, I bred a bunch of things in this particular space. I don't think I read this specific one. 

[01:00:24] I think there's a nice article that the React team has put out in this particular page as well. It is, uh, I think the world has come to the same conclusion, which is that we have these replayable apps and it's a problem and we need to break them up. And so what's happening here is it basically, they're saying like, let's create these islands, that can be lazy loadable and there's all these constraints that automatically come with these islands. Right. And all have to do with, like, how do you share data between them and when do you know when to wake up these islands and so on and so forth. Right. And, this is great. Qwik takes this idea to the absolute extreme, it says like every component is an island. 

[01:01:06] What do I have to do in order to make every component island? I need a way of passing complex data into this component in a way that serializable. So there's a whole architecture around, how do you take the data and serialize it into the dominoes that we still, you know, the most obvious version of better, which was the Q objects. 

[01:01:21] Right. But there's a lot more that I didn't cover. So all of these things have to be done and solved. We need a way of knowing when individual islands need to be woken. Right. Um, which I'm sure they didn't have even discussing over here because it's a problem that you run into later, right? If I interact with one items, for example, a carousel in this particular thing, how do I know that I have to wake up by a header or the sidebar or any other piece of the UI? 

[01:01:45] Like, I need to know this somehow and you can say like, well, that's a developer's problem, but that doesn't actually solve anything. Right. And this is what Qwik is, is good at, is that because it can serialize all these pieces of the DOM. It then knows who is aware of what data. And therefore it knows if a particular data changes do, who do I have to wake up? 

[01:02:07] And so this is absolutely a step in the right direction. Qwik is what happens when you take this, let's take it to an absolute extreme. Yeah.  

[01:02:16] swyx: So, okay. For those who haven't, um, the other two frameworks that are kind of in this vein, are Elder.js on this, in this Svelte ecosystem, by default only HTML, 0 KB of JS, but then you, you, you call out which islands you want to implement, and then that hydrates into Svelte components. 

[01:02:33] Um, so this, this does a bit of that partial hydration.  

[01:02:37] Misko Hevery: And again, you have to talk about like, well, how do I know when to do it? And if I wake it up, like how do I set up listeners on it? And then those listeners, how do they know when to wake up other islands? Like all of these things, I kind of glossed over in these particular thing, because you know, people know that we'd have to go this direction, but they don't know what's waiting for them when they go for the. 

[01:02:55] swyx: Yeah. Yeah. So just pointing out the alternatives that the other people working on.  

[01:02:59] Qwik Event Pooling 
 
[01:02:59] swyx: And then one final question, I think I have, something React has sold people on is that registering event listeners is expensive and that's why we have synthetic events. Is that true? Do you have a view on like synthetic events and whether or not we should have them? 

[01:03:18] Misko Hevery: Can you tell me more about it?  

[01:03:19] swyx: Okay. So instead of registering independent event on every single component or tag, R eact only will registers one root listener and that's everything bubbled up to that root.  

[01:03:32] Misko Hevery: Yeah. That's exactly what Qwik does yet. Okay. Now the thing is, well, when you do that and you have a global listener, now you have a problem, which is like, how do I backreference and figure out which callback to call, right? 

[01:03:47] When React needs to somehow walk this tree and figure out where is that actual closure? Like end of the day, I have to call a closure, right? So where is that closure that I need to call to do this? and the problem is these closures are not serializable, right? Whereas in the world of Qwik, we ex we also have synthetic roots and there's, where's my share button. 

[01:04:11] swyx: I should mention that synthetic events are primarily for cross-browser compatibility. Um, but there's still the, there's the concept of event pooling in React. And there's still a concept of bubbling. 

[01:04:21] Misko Hevery: So let's take this particular thing, right? So what happens is there's a global listener, not to top, you do Keyup, it bubbles up, the global listener catches it, goes back up and says, okay, this is where it originated. 

[01:04:33] It looks for on KeyUp event. It finds, it finds a URL. And that URL points to, uh, this, this guy right here, right. This thing has amnesia, right? Like it just kind of woken and it has no idea what's going on. Right. It's it's like call it amnesia. Right. So one of the things that the QRL has to do is to recover the state. 

[01:04:54] And this is something that happens back in the back without you thinking about it. Right. So the QRL wakes up and says, okay, I'm these, you have no idea what's going on. Let me go recover this. And let me go try to compute the state, get the props, everything I need to execute this function. Right. Which is why, when you look at this, you see the script that contains the state. 

[01:05:14] When I first click on something that's script tag gets consumed, it gets its disappears, right? Because that's when the system woken up with an amnesia and said, oh wait, where's my stuff. Right? And it goes, look for it, finds all the pieces and then determines that this component has this "2kz" object which is right here. And so we've decentralized that and places in the middle of the application and, um, gets them going. So, this is very similar to synthetic events. The difference again, is that we take, uh, we take it to the extreme of saying on the end of the day, this is just function. 

[01:05:49] That is somewhere that I can lazy load them to execute, and I have to restore the function state and then let it do its job. Right.  

[01:05:57] Qwik Conclusions 
 
[01:05:57] swyx: Cool. Sorry for like the really random, did deep dive, but I feel like these are questions that people have when they compare it with  

[01:06:02] Misko Hevery: what they know. 

[01:06:02] I think those are excellent questions. And if I can leave one thing is that don't think of this stuff as yet another framework, right. We already have plenty of other frameworks out there and I'm going to argue that they're pretty much. In terms of the capabilities. Uh, this is not trying to be at another framework. 

[01:06:21] This is really striving to solve a set of problems that we are faced with every single day. And we don't have good solutions for we, this is really trying to solve this sufficiently advanced compiler, which I believe is not achievable unless, you cooperate and the reason it's not achievable again, it's like, imagine you go to the developer and say, go put me at least a lot of boundary over here, that person will spend weeks, right. 

[01:06:48] And refactoring, and maybe where they want to even be able to succeed in this particular location. Right. Because the whole thing needs to be rearranged, right. The compilers cannot possibly be.  

[01:06:58] swyx: And I would just observe that you could use React inside of Qwik. You're already using TSX and  

[01:07:04] Misko Hevery: you can, one of the goals for me is I don't want to write, I have to be responsible for writing widget library. 

[01:07:09] And so I'm thinking super hard, how I can just consume. Widget libraries can I think it's possible. There is, there's a couple of caveats, but yeah,  

[01:07:19] swyx: I think that those are closest to Astro, but with a bit more fine grained loading than Astro offers , which is pretty cool. You might want to, you might want to check out, Astro's data loading on the server side of things which could be interesting.  

[01:07:31] Lessons from Angular 
 
[01:07:31] swyx: Okay, cool. I want to zoom out a little bit and spend a little bit of time on Angular, and then we'll do your Ted talk. So a lot of the things that I hear about Angular are sort of second party, third party type of stuff. 

[01:07:40] What did you learn from the adoption of Angular that you 're bringing over to the adoption or rollout of Qwik?  

[01:07:47] Misko Hevery: That's a good question. It's a really good question. I love it. I think Angular was lucky in a sense that it was a framework when there were no other frameworks in the JavaScript ecosystem. 

[01:07:57] Right. And so in that sense, it was the first one, you know, what we had before Angular was GWT, yes, which is not a framework, it's a trans compiler. Um, we had jQuery, which is not a framework, but kind of a hacky way of modifying the DOM. And I don't mean this in a negative way. It's just, it's just not a framework. 

[01:08:18] Uh, we had, uh, there's Marionette and Backbone, right. Which lists kind of framework-ish, but really only about how to track data. So it was really a subscription for data model rather than actually how to render things up. So, so in that sense, I think, Angular.js defined its own category. And I think this is the reason why it was so successful because there was a need and the world needed this and recognize that it needed it. And so we just went after it. Um, since then there's bunch of other frameworks that came afterwards. All of them have unique ways of improving on this idea, and, you know, React took the idea of functional and went crazy with it. 

[01:09:00] And I think it's wonderful, Svelte took the idea of actually true reactive system where you have subscription things and you update only when it's necessary. And I think they did a great job and there's many things in Svelte that I really, really like, like all these frameworks have, have some amazing things in them. 

[01:09:14] Uh, but at the end of the day, they're still solving the same problem. Right. They're still in the same space. Uh, and they're solving it in the same way, in a specific way, in the same way. I mean, like we're pretending we have a desktop application and we pretend to be all the code is available for us. And we pretending that we can just like, do whatever we want. 

[01:09:33] Right. When in reality, we're not a desktop application, we're a mobile application, but the code isn't available to us, there is a cost to start up all these code. And so, we have a new set of problems that we created and the new sort of problem that we have right now is how to start up the apps quickly. And I was just chatting with, um, somebody from Airbnb, uh, Elliot , he was a good buddy. He actually worked with me on Angular.js. They use back in the day. And he was just saying how they spend man-years trying to rearrange their homepage because it's a react application in such a way to make it startup that fast and what they essentially ended up doing. 

[01:10:12] Through a complicated set of hackeries is lazy loading the individual components over time. Right? So the lazy load, the first one first, and then get the other ones going downloaded that are below the fold when you have nothing to do. Right? And so the solution is the same that everybody knows what the solution is. 

[01:10:31] Uh, everybody's trying to do the solution, but the current set of frameworks are just fighting it tooth and nail. 

[01:10:38] One way that they're fighting tooth and nail is for example, that the rendering pipeline is fully synchronous, right? Uh, in all the frameworks, when you say render, you know, everything that you need to render better, be around otherwise bad things happen. 

[01:10:52] Right. And that means that all the code has to be around. And that means that there is no good way to just say no, I just want to render this component. I don't need to render its children and I don't need to render its parent. I just want to run them. The component in isolation and existing frameworks don't know how to. 

[01:11:10] The other thing that existing frameworks don't know how to do is again, storing the state. Like how do I store the state in it? So the thing that I've learned from Angular.js days is make it really palatable, right. And solve a problem that nobody else has doing yet. Another framework in this state of our world would be complete suicide cause like it's just a different syntax for the same thing, right? 

[01:11:33] So you need to be solving a problem that the other ones cannot solve.

[01:11:38] And I'm actually going to go on a limb and say like, they cannot solve this. There is no way to add these kinds of fine grained, lazy loading to Angular, React, Svelte or any of these other technologies, because doing so would be such significant breaking changes that you would end up with a different framework. 

[01:11:54] And the individual communities wouldn't stand for that. So there is no way for React to get these capabilities. There's no way for Angular to get those capabilities and so on and so forth. That's good and bad, right? It is good. Because it creates a, a value that nobody else can provide. 

[01:12:11] It is bad because it causes a rebrand. But Hey, this is where a Builder.io comes in because Builder.io has Mitosis, which allows us to consume one format and generate many other formats. And this is why I think something like Builder.io and Qwik makes so much sense, right? Because Builder.io has lots of existing companies, lots of existing content, lots of need for speed.  

[01:12:38] Qwik has the answer, but it requires migration, but what Builder.io migration is trivial because while we just generate another output. 

[01:12:48] swyx: Got it. Yeah. Well, I feel like I'm basically, we we're missing a term for this, uh, for what you're trying to do. Uh, you keep saying framework, but we don't have a better return than. Um, so I'm thinking like, you know, like app, loader, uh, something light, something, something super light that emphasizes that you're not directly competing with, uh, the other frameworks because you'd use them together. 

[01:13:12] Misko Hevery: You know, when I first started Qwik, I actually wanted to use React as the rendering engine. It turns out for many reasons that it's not possible as I pointed out, the fact that React wants to be fully synchronized kind of ruins your day, uh, in this particular department.  

[01:13:24] But yeah, I really don't want to make another framework in that sense. Right. And, um, this is why I'm using JSX and as much stuff as possible, which is, you know, how do I do least amount of work and solve the problem is kind of the mantra that I'm after.  

[01:13:39] swyx: Yeah, absolutely. Or maybe, I don't know.  

[01:13:40] Qwik vs Angular Ivy 
 
[01:13:40] swyx: how does this compare to (Angular) Ivy? 

[01:13:42] So know if it's a  

[01:13:46] Misko Hevery: hot take. That's a good one. So Ivy was, so if you go even further back, about three years ago at ng-Conf on the keynote, I give a talk that basically describes Qwik, right there. I was just like, we need to do this. We need to do this, this, this, this, this is us. Right. And then nothing happens. 

[01:14:03] Like I gave the keys to the kingdom and nobody did anything. I  

[01:14:07] swyx: mean, what are you talking about? You're on the team.  

[01:14:10] Misko Hevery: Well, I'm in like the community, not thinking of the computer, nothing in nobody in the outside world, be like, that's a good idea. We should do this. And like, let's solve it or let's attack this problem. 

[01:14:18] Like nothing happened in the community now, internally Ivy was a stepping stone to give us that capability so that we can do all of these things. And I think Ivy in essence was kind of a success. Uh, the numbers I'm hearing from my friends saying how they're saving ridiculous amounts of CPU, uh, at Google, just because of how more efficient, uh, IVs on compilation and also on a runtime CPU and how much more productive the engineers are because there are turnaround time for the applications are quicker and so on. 

[01:14:49] So if all of those measures Ivy was a success, but I had a hope for Ivy that Ivy could be a stepping stone for this lazy loading technology. But now that I fully understand the nuances of it, all, it turns out there's no real way to do it again without introducing such significant break and changes that will be unpalatable to existing customers, right? 

[01:15:11] And that is the crux of the problem. Like an, the end of the day, you have to write your code differently. You cannot, uh, nest, you know, 20 closures on top of each other, and then expect a sufficiently smart compiler to detangle that stuff. Not gonna happen. Right. So instead you need to provide guide rails for the developers so that they can appear as if they're nesting 20 closures on top of each other, but they're actually not so that the tooling can come separate all this stuff out, break it all up and do all this magic. 

[01:15:44] And on top of that, it has to be done in a way that is resumable rather than replayable right. Because even if you can have a sufficiently complex compiler for React, that separates all of this stuff out, it still wouldn't help you because in order for React to figure out where the listeners are, React has to execute all of this code. 

[01:16:05] Right. And so even if you had this, you still wouldn't solve the problem. Yeah.  

[01:16:11] swyx: Yeah. Yeah. Cool. Um, well, that's, uh, that's, uh, kind of what we planned, uh, talking web dev wise, I thought that was really cool meeting you, sharing and sharing about, uh, you know, what, you know, I think, you know, your, uh, your enthusiasm is just amazing, honestly, like, uh, if I was, you know, if I meet Angular and I, you know, I spent like 10 years, I don't know, what was it, 10 years? 

[01:16:35] Uh, I don't know. Um, you know, I would, I would just be done. I would just be like, Hey guys, that's someone else do this, but you're still in it. You know, you're, you're still, you're still like iterating on feedback that people gave you two weeks ago. And, uh, it's just, it's just amazing to watch. And, uh, so I hope that people are at least inspired to, to, to push the boundaries as much as you do. 

[01:16:55] So. Yeah. Yeah. I think that's, that's really cool.  

[01:16:58] TED Talk: Metabolic Health 
 
[01:16:58] swyx: Okay. So final question, which I'm trying to implement right now. If you were asked to give a Ted talk about something that you're not well known for, what would it be? 

[01:17:07] Misko Hevery: So my friends oftentimes get annoyed because all I talk about, but I don't know about computers. 

[01:17:13] There's another topic that I talk about and that is metabolic health. Let's do it. And my friends are annoyed with me because like it's all I'm doing. And I have crazy opinions on this particular topic. Um, anyways, metabolic health is, it has a lot of different names, right. But it is the root cause to obesity, to cancers, to many different things. 

[01:17:37] Um, and it is one of those things that people just ignore and don't worry about. Right. Uh, I was just saying how I went to Europe, there's jar to the conference and, you know, everybody was in great shape, et cetera. And then I was getting back to the, on a place. To the U S where only a U S citizens allowed to fly back right now because of the COVID right. 

[01:18:01] The whole line was bunch of metabolically, unfit people. It was insane. And I, like, I was, I just spent a week in, you know, in Europe where everybody was fit and beach and  

[01:18:15] swyx: everyone's hot,  

[01:18:16] Misko Hevery: and then you go back and you go, like, what are we doing wrong here? Uh,  

[01:18:22] swyx: and then, well, so what do you mean? Is it different from regular health? 

[01:18:26] What does metabolic health?  

[01:18:28] Misko Hevery: So, okay, so, um, long time ago, uh, when we know when we were a single cell organisms, uh, there was a symbiotic relationship, formed between the main cell in a symbiotic cell, which became mitochondria. And mitochondria has a separate DNA. It has circular DNA. Like our DNA is like this complicated thing that is rolled up. 

[01:18:52] Right. But mitochondria has circular DNA, just like a bacteria does. And so it looks like somewhere along the line, we consumed a bacteria and that bacteria took permanent residence inside of ourselves. And what this particular bacteria is really, really good, good act is, uh, breaking down energy, uh, whether it comes in the form of carbohydrate alcohol. 

[01:19:17] That's and there's lots of, lots of different paths. Uh, whatever thing you have that you can get energy at, not the contrary is really good. Um, chewing down on that thing and spitting out this other thing outside called ATP adenosine triphosphate and all of the, uh, cellular or mechanisms, all the enzymes, everything on a body, all the machinery that we have runs on ATP, right? 

[01:19:40] So you can think of this as themitochondria is the ATP generator. There is out mitochondria can get sick by feeding it the wrong kind of fat, feeding it too much, alcohol , feeding it too much sugars, fructose, all kinds of other things. And when mitochondria get sick, bad things happen. And, uh, they ended up being everything from high blood pressure to insulin resistance, back to diabetes, to being overweight then, and it all basically goes back down to this crazy amount of. 

[01:20:10] swyx: Interesting. So how does that affect your diet? Like, is it, is it mainly diet? Is it, is it some extensive?  

[01:20:16] Misko Hevery: So, um, my take on this particular problem is that, uh, anything that will improve insulin resistance is going to be better, right? So if you change your time and your approval, insulin resistance, that's going to be better. 

[01:20:27] Uh, certainly exercise improves insulin resistance. So exercise certainly helps. However, as a people are fond of saying is you cannot outrun a bad diet. Like I think diet is like 80% and exercise is 20%. I'm not dismissing exercise by all means. I go to the gym every morning and I wake up and I go to my garage and I lift weights because I think it's important in healthy. 

[01:20:50] Right. But if I don't get my diet under control, Any possible game I can get out of weightlifting is going to be destroyed by crappy diet.  

[01:20:59] swyx: what rules do you have for dieting or not dieting, but more just general.  

[01:21:05] Misko Hevery: Yeah, so I avoid everything, uh, that spikes insulin. So people usually call it the ketogenic diet  

[01:21:12] swyx: Hygienic food who,  

[01:21:14] Misko Hevery: yeah, so, but I like go to the extreme and I just like avoid everything that could basically, if it has carbs, I don't want it. 

[01:21:21] But more importantly than I think than carbs is, uh, is, is seed oils. So seed oils are, I think the, the thing that messes up your mitochondria and once the a hundred is messed up, then a normal load of carbohydrate. The normally amount of fungi, I wouldn't have a problem with becomes a problem.  

[01:21:43] Sesame  

[01:21:44] swyx: Oil? Yes. So  

[01:21:46] Misko Hevery: don't I don't do that. 

[01:21:47] That's cruiser corn oil, soybean oil, like all this other stuff. Go on online.  

[01:21:51] swyx: How do you cook?? With no oil?  

[01:21:53] Misko Hevery: Lard. I eat lots of fat. I'm just don't eat seed oils. Okay. Sorry,  

[01:21:59] swyx: you said, you said go online and go here,  

[01:22:00] Misko Hevery: go online and Google, how seagulls are manufactured. There's a good one by, you know, how it's made or how it's like one of those things on discovery channel. 

[01:22:08] Have you seen those things?  

[01:22:10] swyx: I'll look  

[01:22:11] Misko Hevery: it up. It has nothing to do with health and anything. It's just really like, they go to random factories and they show you how this is made, how that is made. And so there's one that talks about like how seed oils are meeting. It ends. It's the same process. Because there's like crazy chemicals. 

[01:22:25] They have to dissolve it and raise the temperature, lower ed than it stinks so bad. Nobody would drink it. So they have to purify it and bleach it and then it has no color. So they have to add color to it. It's like, what? Like how can this possibly be good for you?  

[01:22:40] swyx: It tastes good. That's all I know, but okay. 

[01:22:42] All right.  

[01:22:43] Misko Hevery: Because we put stuff in it to make a piece good. Cause it's it's flavorless, right? Because we bleach them before then. Originally it was such bad smelling thing that we had to bleach it to get the smells out of it and make it white. And then we have to add food, coloring to it, to make it yellow. 

[01:22:58] And then we have to add any kind of flavoring into it so that it actually is palatable. It's like, what are you doing? Like, and the craziest thing is that somehow we convinced ourselves that that's healthy.  

[01:23:11] swyx: Yeah. I don't know if we've convinced, like it's just normal. That's all, that's it. It's just, that's how I learned how to cook, you know? 

[01:23:17] So  
 
[01:23:18] Misko Hevery: I noticed, so the way I, uh, I noticed this interesting thing, which is that I would, when I was at Google, I would have breakfast in the morning and I would have a bunch of eggs. Cause I love eggs and I would feel miserable after the breakfast. And I will be like, ah, I'm going to slug it. Oz is just, and naturally people are like, oh, it must be the eggs. 

[01:23:38] Cause the meat and animal products are bad for you. Right. And then I went to Mexico and I had a whole bunch of eggs on a vacation and I had a whole bunch of eggs. And I was like, fine. I was like nothing wrong with it. And I'm like, what's the difference? It's the same egg. What else is the difference? The difference is in Mexico, they were using lard to cook my eggs on. 

[01:23:55] Whereas in Google they use old bread oil. Right. And then I did a whole bunch of experiments at home and I realized, well, my gosh, it's the fricking oil that makes me feel miserable. And then you slowly kind of realize it's just the seed oils that are doing this. And if you read a bunch of literature, it turns out other people have come to the same exact conclusion that seed oils are problem. 

[01:24:18] And CTOs are super high in omega six, and it turns out omega six, uh, incorporates itself into the membranes of cells and makes those membranes not flexible, makes them stiff. And that kind of messes up the a hundred and then the conjure has troubles and then it will help. Oh man.  

[01:24:33] swyx: Okay. I got it. I gotta change it. 

[01:24:36] Misko Hevery: Little poison. You overlay two decades. Jesus.  

[01:24:40] swyx: All right. Well, cool. Um, well I think, I think that might actually say some lives today  

[01:24:46] Misko Hevery: or people will think I'm crazy.  

[01:24:48] swyx: Uh, so I think you're basically for a lighter JavaScript and lighter body, so, 

[01:24:55] um, cool. Um, yeah, thanks so much for, uh, for joining me on this, uh, on this chat and I learned so much today. Thanks. Thanks so much  

[01:25:04] Misko Hevery: for having me, man. This was so much fun. 
[Weekend Drop] Miško Hevery: Qwik, PartyTown, and Lessons from Angular
Broadcast by