Building a Web-App: The Easy Path and the Performant Path. Why Are They Not the Same?

Rate this content
Bookmark

We use frameworks to make building our applications easier. Yet as the application scales, its performance suffers. There is no one thing, but rather a death by thousand cuts. Developers are under pressure, and they often choose the easy and quick path to deliver a feature rather than the performant path. The performant path is usually more work. So let's look at these two paths and imagine a world where the performant path is the quick and easy path.

This talk has been presented at JSNation 2023, check out the latest edition of this JavaScript Conference.

FAQ

Builder.io is a headless visual CMS system that is not hosted. It allows users to npm install it inside their applications, drag and drop components, and achieve visual editing capabilities. It facilitates the registration of custom components, enabling marketing personnel to modify landing pages without needing engineering assistance.

Hydration is a process used in web development where a server-side rendered page is made interactive. Initially, the page is sent as static HTML from the server, appearing quickly but without interactivity. JavaScript is then downloaded and executed to bind event listeners and make the DOM interactive, a process known as 'reconciliation' or 'hydration.'

Partytown is a technology designed to enhance website performance by relocating third-party JavaScript code to web workers. This approach minimizes the main thread's workload, leading to faster interactions and improved user experience on the website.

Mitosis in web development refers to a process that allows developers to write code once and generate canonical code for multiple frameworks such as React, Angular, Vue, and Svelte. This helps in maintaining a single codebase while supporting various frontend technologies.

Resumability is an alternative approach to web application loading where the initial HTML contains all necessary information, including where event listeners are located. This allows for immediate interaction upon page visibility, without waiting for JavaScript to download, thus speeding up interactivity and reducing JavaScript size by eliminating duplicate data.

Quik optimizes web application performance by introducing concepts like signal and code extraction. These concepts allow the compiler to perform optimizations that ensure constant startup performance regardless of application size, support lazy loading and execution, and minimize the JavaScript needed for initial interactivity.

In Quik's architecture, the service worker pre-fetches necessary code segments as the user navigates the application, storing them in cache. This ensures that when interactive elements are required, they can be retrieved quickly from the cache, reducing load times and enhancing the user experience on slower or unreliable networks.

Miško Hevery
Miško Hevery
31 min
01 Jun, 2023

Comments

Sign in or register to post your comment.

Video Summary and Transcription

Misko Havry introduces himself and discusses the impact of JavaScript on performance. The concepts of reconciliation, hydration, and resumability are explored, along with the importance of clean code and compiler optimization. The Talk includes demos of application components and showcases the power of code extraction. The QUIC framework is highlighted for its ability to optimize code loading and prioritize interactions. The service worker is used to selectively download components for improved performance. SEO and debugging in QUIC are also discussed, along with comparisons to other frameworks.

1. Introduction to Misko Havry and Performance

Short description:

Let's get started with a joke about how functions break up. I'm Misko Havry, the creator of AngularJS and Quik. We also have Partytown and mitosis. Let's talk about performance and how JavaScript can impact it.

So, with that, let's get started. Happy Android. Thanks, guys. Thank you. I think we also need to give applause to our emcees. I could not do their job. So I'm going to start with a joke, because I love dead jokes when I'm a dad. So how do functions break up? They stop calling each other. And it's actually a relevant joke. Because we're going to show you how the functions break up in this presentation.

So hi, I'm Misko Havry. You might know me, because I've done this thing called AngularJS, and now I'm working on this thing called Quik, and hopefully you've heard of builder.io. It's a headless visual CMS system. What it is, is Imagine Wix, but not hosted. Instead, npm install inside of your application. You drag it in and then you get visual editing. And you can also, because it's your application, you can register your own components with it and have your marketing people go wild. And they don't have to bug you, the engineer, about changing anything on their landing pages.

Now, we do other things too. We do Quik. But we also have this thing called Partytown, which moves third party code into web workers. And we do mitosis, which allows you to write your code once. And we generate canonical code for React, Angular, Vue, Svelte, and anything else that you can possibly imagine. But let's talk about performance. So this is kind of a typical randomly selected set of websites from the web. And notice, they're all kind of green, maybe some yellow. It really isn't looking that good. Why is that? You know, if you build a simple hello world app and you push it somewhere, the performance is great, but once you put real applications, you know, real traffic behind it, the performance doesn't go so well. And there's a lot of different reasons for it, but one thing I'm really going to try to convince you of is that it is JavaScript. And basically, too much of it.

2. JavaScript and Hydration

Short description:

This is a chart from HTTP archive showing the increasing amount of JavaScript being sent to browsers over time. Users expect complex applications, which require JavaScript. The more JavaScript shipped, the lower the light house score. Hydration is a workaround that creates a problem. Previously, applications would boot by sending empty HTML and loading JavaScript. To eliminate the white screen, server-side prerendering was introduced, but it lacks interactivity until the JavaScript is downloaded and executed.

And if you look at it, this is a chart from HTTP archive. This is the amount of JavaScript that we have been sending to our browsers over time. And as you can see, that's just going up, up, up. And I'm going to make a bet that in the future, there's even going to be even more JavaScript. And it totally make sense because our users experience expect complicated rich applications. And you cannot deliver complex applications without JavaScript. And so we need JavaScript.

You know, there isn't the world where we stop shipping JavaScript or is there? So this is another interesting graph from HTTP archive. I've selected a few frameworks here. This is not important. What I want to show you here is that the median score that the website gets and the amount of JavaScript that's being shipped are essentially inverse of each other, right? The more JavaScript you ship, the lower your light house score. And the less JavaScript you ship, the better your light house score. That shouldn't be surprising. This should be like self-evident, right? That the less JavaScript you ship, the better the thing will be. The problem is that the way our applications work is we have this thing called hydration.

And hydration is this interesting workaround we have created and is creating this problem. So let me explain. Back in the day before we had meta frameworks like Next.js, the way the applications would boot is we would send HTML. The HTML would be empty. And into the HTML there would be a script tag that would load JavaScript. JavaScript would execute your application, the application would cause a render and then the render would make a website and now you can interact with the website. But we said, you know what? We really don't like the fact that there is this whitescreen there for several seconds. We really want to get rid of that. So we said, you know what? We know the solution to that. We're just gonna go server-side prerendering. So, we sent now a bigger HTML, notice the HTML got bigger, and now the page isn't white. It's the actual application that you have. But guess what? You cannot click on it. It appears faster which is great but you can't have any interactivity on that page yet. So at this point we download the JavaScript, execute the application.