Placeholder Image

字幕列表 影片播放

  • wear anxiously waiting.

  • I mean, you know the way, um that I hope you have a way to see if the way it's always give away.

  • All right?

  • Right, right.

  • Right.

  • Yeah, we got think.

  • Good.

  • Press press.

  • The first thing is the thing, right?

  • Okay.

  • We could go the full screen f for full screen.

  • There we go.

  • Yeah.

  • Oh, okay.

  • Right.

  • Ah.

  • So earlier this year, a few of us went on a fact finding mission to India to see how folks who used the Internet out there and one thing stood out to us, and that is that feature phones are back.

  • Yeah.

  • The future phone market doubled in 2018 in India and the sale of smartphones like, kind of flattened out.

  • And at the current rate, that is projected 400 million feature phones will be sold in India this year alone.

  • Yes, and the one on the right over the very foreign.

  • That is geo phone, which is the most popular brand.

  • And it costs just £15.

  • And I compared to all of the phones you all have here, everything about all of these phones is extremely shit.

  • It's 240 pixels wide.

  • It's single pixel density.

  • There is no touch screen, and the CPU is God awful.

  • But it's 15 quid and that allows people to be on the Internet that previously couldn't afford to be there.

  • Yes, and also the geo phone on the end There, this is a web based phone is running Chiyo s, which is a fork of the old Firefox os.

  • So this phone is kind of is running Firefox 42 for pretty much everything s o a little team of us got together consisting off summer Jake on Dhe Americo she she she's in America might market in America.

  • America is that way.

  • If you if you actually think it's quicker to go that way, Yeah, you Either way, if you just keep going forward, you find it.

  • Um, yeah, What?

  • We want to see if he could.

  • We build an interactive Web experience that would run on devices like this.

  • But, you know, with responsive design and progressive enhancement and enabling it to also scale up to something that looks great on a desktop.

  • Yes.

  • And that thing became frocks.

  • It is a game.

  • If you like mine sweeper, you will like rocks because it's the same.

  • Play it now on proxy dot AP.

  • So here's on desktop and, as you can tell, like we threw all the animations at it and, like, make it fancy.

  • But keep in mind this entire thing scaled down nicely and is playable on one of these 15 quid feature phones with the exact same code base.

  • Yes, we put a lot of effort into making it run really fast.

  • So we figured we'd go through some of the tricks and techniques that we use because none of it's really unique to this particular Web.

  • It's stuff that you can apply to any site till all right about before we dive in.

  • I think it's important that we address a question that we still often see on Twitter.

  • Yes.

  • Should I care about performance?

  • Should I care about performance?

  • Should I care about performance?

  • Yeah, yeah way.

  • Think I'll go to our call for this?

  • Is this one on Web fundamentals there by Jeremy.

  • Jeremy, where are you?

  • Where is he?

  • He's he's actually here.

  • Is he here?

  • He's supposed to be a guy said to me last night, Really?

  • Looking forward to your talk.

  • Jake, where are you, man?

  • It's just rude.

  • Fine.

  • Well, okay, Well, if you want to read Jeremy's article, whatever you can find it at this Billy Link.

  • It's like it points to all these Web performance studies carried out by a variety of companies such as Pinterest, who reduced their perceived wait times by 40% and saw an increase by 15% in sign ups or cooker.

  • Reduced Arlo time by under 15 seconds and start increasing conversions and session time.

  • BBC lots in addition time.

  • So if you ever since the painting to load or anything, he was space time by half, 12% boost in sales.

  • I don't take it from that over.

  • If it's abandoned 230 seconds, conditions apply right, although that's a large variety of sites like, we'd still see folks saying like me, this Yeah, it's all very interesting, but it doesn't apply to my site because, like my sight is somehow difference.

  • Yeah, they found, like, one aspect in the study that they feel like their own site doesn't match two, and therefore the entire evidence provided is invalid.

  • We don't buy that now.

  • I think everyone in this room right is a user of software.

  • We know how frustrating it is when something performed badly.

  • And low time is just such a big part of that.

  • The performance optimization So we're going to talk about in this talk are pretty simple.

  • That easy.

  • Literally two minutes on paper.

  • But when you've got a bill system wrapped around your project, as most of us do, just adding something like a tag to a page can become like a real pain.

  • So we're gonna take a look at that side of things as well.

  • So let's rewind to the first Alfa version off approx before we had done any of our performance work.

  • Yes.

  • This is totally the real Alfa version, not the version we just retrofitted for the sake of the shut up.

  • You're ruining the illusion.

  • I'm sorry.

  • So, aside from being a bit slow, it wasn't really all that different from your average everyday Java script of a nap.

  • Yeah, So action.

  • I was pretty basic, right?

  • You contend?

  • Little bit of meta data.

  • Jarvis, we file that took care of populating the page.

  • We've got style sheet there.

  • That star she is just for a web front.

  • The rest of our CSS was embedded in our job script by post.

  • Yes, the notable difference from most weapons, I think, is that we used pre act instead of react.

  • React is 33 day pre act is three cake React can do much more, but none of the things that I can do more we actually needed.

  • For us, it was really like a no brainer to be able to save 30 case straight out started.

  • Yes, absolutely.

  • The other differences we used roll up basically because we wanted to give it a try like we'd use roll up in before for, like, libraries and stuff.

  • But but not for full Web maps.

  • So you see, last year we build a Web called squash and to build smoosh, we used weapon.

  • And when I say we, I really mean our colleague Jason, who handled the weapons out of things and he's in America, basically had to make use off lots off undocumented and internal Web pack AP eyes just to achieve basic stuff, and he has years off my pack experiences really comfortable with it.

  • The two of us, on the other hand, don't yes.

  • So as a result, like We didn't understand the Project Bill system if something went wrong that was not in trivial, which most of it was non trivial.

  • Well, can't help us until Jason woke up on the other side of the world and talking to some other teams internally and excellent.

  • We hear similar stories.

  • There's like one or two people who are considered the Web pack whispers on the team.

  • It's their sole job to, like, maintained the build system, and nobody else actually really dares to touch it.

  • And maybe this sounds familiar to some of the people here in the room.

  • Yes, s O When I use where pack.

  • I don't feel like I'm using JavaScript.

  • I feel like I'm switching like pulling levers, switching switches.

  • And I got massive conflict objects like herding lots of plug ins around of varying quality that often don't really play well together.

  • Yeah, and so we tried roll up and we found lots of plug ins off varying quality that don't really play well together.

  • But the big difference is mere mortals can write their own plug ins.

  • Rollup has its simple, well documented plugin system, so it's easy to get involved in the innards of the build.

  • If you know enough JavaScript to wrangle of weapon convict, you know more than enough to write a roll a plug in and we knew we were going to do unusual stuff.

  • It was clear to us it on these super low and feature phones.

  • It's gonna be hard to have everything on the main threat.

  • So we wanted to make workers it coop part off our architecture straight from the start.

  • Yes, and there's, you know, the problems that we now have multiple threads.

  • And the problem is that there's often share dependencies between the Smallville plant experts.

  • So that's all that we use comlink and that facilitated communication between workers.

  • The mainframe.

  • It's a library that you wrote.

  • But that means that lively needs to appear on all of the workers and on the main Fred now Web pack can't share chunks between workers and the main threat so use would end up downloading it well at least twice, once for every worker plus one.

  • And this what happened for each additional shared dependency and roll up kind of handles us for free out of the box because it leaves the choice off format up to you?

  • Yeah, he wasn't just job script needed hand alive because, you know, we need to add HTML as well.

  • And there is a weapon a plug in for you to create html for your project.

  • But here is the code for that plug in, and it's massive.

  • And again it relies on loads off internal and undocumented parts off weapon.

  • Yeah, this was looking is so big.

  • It has its own plugging ecosystem as well, and it's kind of the way it works.

  • It doesn't really want you touching the HTML itself.

  • Instead, it wants you to learn the configuration options and the all of that, and learned all of their quirks as well.

  • Like it turns out that your skills in HTML, which I imagine many of us already have a completely useless when you're using this building.

  • So we try to find a cripple unplugging for role of and couldn't find one to make this comparison fair.

  • So we decided to write our own.

  • So roll a plug ins are just functions that return objects.

  • And that object has a name.

  • Ki just so that you're plugging can have a name and rope can generate nice messages and debug messages.

  • And the rest of his object are just call backs for the various stages off the built.

  • And these are all very well documented.

  • Yes.

  • So the one we're gonna use for this one, we're gonna use the generate bundle hook Mrs called just before it writes everything to disk.

  • You get the options.

  • That roller was called with the on.

  • You also get this bundle object which looks like this.

  • This tells you everything about the build, you know?

  • So So it's for the JavaScript.

  • For example, You get the initial pass, the source file, you get the output file name, which has been hashed for long for future cashing, but also loads of other data, like dependencies and which exports it has.

  • And even for non jobs.

  • Got files you do get.

  • It's upset off this kind of information.

  • Did I go too fast for you?

  • Might not give you time to open a bottle.

  • Sorry.

  • Is that the fizzy water world is still war.

  • I feel very strongly about this stuff, which is still all right.

  • Okay, I'm gonna I'm gonna get one ready as well, right?

  • Um, yes.

  • So this is the whole bill Come big tells us everything about what's going on inside roll ups, little world that we can use this to create our HTML.

  • So what we're gonna do is we're gonna load in E.

  • J s templates and compile it.

  • And now you know, we're just using a Jesse's an example.

  • Well, it's it's the one we use, but you can use any template in language you want.

  • Like Roller doesn't care.

  • All he cares about is it.

  • It wants to know about this HTML and it wants to know where to write it, too.

  • S we're gonna use roll ups, admit file method.

  • There, you tell it's an asset.

  • Give it a file name.

  • You give it the source of the HTML.

  • And now roll up will write that file along with everything else.

  • Eso Here's our templates.

  • We've got a placeholder here for the job of script file name which we don't know ahead of time because, as it had roll up will add hash to the final name.

  • So we need to pass in that final final name into our template ing engine after hashing and we can get this, as I said from the bundle object since it tells us both the input path and the output path.

  • So we create little helper here called Get Jess, which we just go so the bundle and finds the corresponding file?

  • Yes.

  • So now all we need to do is add that new plugging into our old con fig, and that's it.

  • We're done.

  • Now you know everything you need to know to write a roll up looking.

  • And I realized that you know, that it's a pretty quick introduction.

  • Just throw it you.

  • But again, compare it to the weapon version.

  • And I'd argue that what rewrote is simply just a little bit simpler.

  • And the good thing is that everyone on our team, I think, felt like they were comfortable with touching that piece of code in adjusting the plugin.

  • If it needed any kind of changing and even better, we're writing code to do what we want rather than wrangling conflict.

  • So if we wanted our html to be a slightly different shape, we could just go into the temple it and change it not to add a new tag, rearrange things, it's just HTML, but what do we actually need to change to make things faster.

  • So I was slow on the slow and on these lone phones.

  • But we need to figure out where proxy was actually using performance.

  • Our tool of choice for testing websites in as real world conditions as possible is webpage test on ork.

  • It lets you run tests on riel device, which makes a big difference and also has an excellent emulation off worst network connections.

  • Yeah, I always like to test on a motor g four.

  • This is a fairly old now phone.

  • It was a mid range phone even when it came out.

  • But it's not dissimilar to the kind of fun is that a lot of people have in the world.

  • We're also gonna test on a three g connection and three G is actually a really good speed to measure.

  • I know we're mostly used to here to look for G and lt maybe even five g soon, but you know often do to signal strength and contention.

  • You will be experiencing speeds closer to three G and sometimes even worse.

  • So here's the results for the very first version of of Rocks before we'd optimized it.

  • And whenever I look at what pace?

  • That's the first thing I look at.

  • Is this film strip along the top?

  • Because that shows us what the user sees as the site is downloading?

  • Yeah, so let's break that down.

  • For the 1st 4.2 seconds, the user sees absolutely nothing.

  • That's what nothing looks like quite literally.

  • No things totally fingers, but out, off nothing emerges.

  • Our first surrender.

  • That's our first render.

  • We can't really count.

  • It is interactive, though until late the user sees the full you with with all of the interactivity and use.

  • It doesn't get that until they have been waiting 5.1 seconds.

  • So we're well over that three second mark that causes 50% of people to abandon, according to some studies.

  • But like we said, we're targeting these $15 feature phones in these $15 feature.

  • Phones are most popular in emerging markets like India, and their speeds, like to G, are much more on a daily basis.

  • Happening so on to G, the user gets 8.1 seconds off absolutely nothing than a pretty useless render, and in total, it takes almost 11 seconds until the user can actually start playing the game 11 seconds.

  • Let's put that into perspective.

  • You saying bolt can run 100 meters quicker than it takes to load our dumb game?

  • So So all in all, the user had to load 62 kilobytes before the site was actually interactive.

  • Surely we can do better, But what is a realistic goal for us here?

  • And that's what I asked Jake to figure out.

  • Yeah, so I went and did some competitor analysis on here it is s o.

  • This is a graph off the size off windows mind sweeper.

  • Over time, it starts off 11 kilobytes in Windows 3.11 That's pretty small.

  • That actually gets smaller, which is kind of amazing, like 9.3 kilobytes and Windows 95 much smaller than approx.

  • The piece of shit we made right, like they're doing really well.

  • But then, in Windows 2000 what?

  • It became bigger seven times bigger.

  • In fact, 70 k.

  • Now this is now bigger than crocks.

  • Size crept up again in Windows X p there.

  • So it's up to 80 k.

  • But then bam, it became 50 times bigger 3.84 megabytes in windows, Mr roughly the same size in Windows seven.

  • But then, bam, it became 25 times bigger.

  • Still, it's 100 and four megabytes in Windows 10.

  • Absolutely.

  • Seriously.

  • Mine sweeper is growing so fast, we have to switch the graft with logarithmic scale.

  • If you sometimes wake up at night and worrying about how you see, it s cold basis growing on proportion.

  • Don't worry, you're still doing better than Microsoft.

  • Yeah, and if you analyze this trend, which we did by 2025 miles, people would be two terabytes by 2030 we predict 2/3 of the planet service will be covered by a single hard drive containing one copy of Windows Mind sweeper.

  • I mean, Tom Burke is doing some great outreach raising awareness of climate change, but really should be worrying about the biggest threat to mankind, which is Microsoft.

  • Absolutely.

  • So you have my conclusion is really that process 62 k Not really doing that badly.

  • So there you go.

  • Thank you.

  • Good night.

  • Thank you for this insightful report.

  • So but on the other hand, we do know that my job can be done in, like, 11 k 10 k.

  • That kind of territory.

  • Eso admittedly Allah version has a bit more going on graphically but still 62 kilobytes to interactive.

  • We should probably reduce that.

  • Yeah, we probably should.

  • So if you want to improve the performance of your sight and you only have a few minutes to spare identify the important resource is that start loading too late on.

  • We're looking at the timeline here.

  • We're getting stuff.

  • We're getting this.

  • Render it, like 4.2 seconds on our job.

  • Script is loaded at that point, so the site is completely ready to go.

  • But it is useless because the text is not rendering.

  • You guessed it.

  • We're using a weapon.

  • A weapon.

  • So we're using space Mona from Google funds.

  • Both the normal and the bold version.

  • And they're about 10 K each, which, as far as Web fund school, was actually not that bad.

  • So why are they giving us so much trouble?

  • Yeah, find out we need to dive into the network panel of Web page test or in death tools.

  • It gives you the same information on Here's the pattern that we were seeing.

  • First up, the HTML downloads the finish line.

  • Here's a convention that both were pitch, test and chrome Deftones actually use.

  • It means it's setting up a new A GP connection and the thicker Linus and the time it takes for request and response.

  • Yes, and once that's done, it will download the CSS, and then it downloads the actual fonts.

  • Now, when you're looking at these sort of diagrams, especially compared to rendering, it's worth noting that don't always exactly aligned.

  • And that's because once the browsers downloaded something, it then needs to pars and executed and then paint it, which takes time.

  • So there's like offset compared to actual painted things on the screen.

  • Anyway, the red flag here is that both the C.

  • S s and the phone files half their own sin line, meaning there's a teepee connection being set up.

  • And this is because the CSS is actually on another server.

  • It's on fun stuff.

  • Google 80 ice dot com.

  • And so it has to start a new connection to actually be able to download that file.

  • Yes, but if you look inside the actual CSS, we could see the fonts are actually hosted on yet another server.

  • So this is fun stodgy static dot com.

  • So that's yet another connection.

  • And the quick fix here is to copy the CSS and the funds to our own server.

  • That way, the browser can reuse the already existing connection and, in theory, referred safe around the second.

  • But wait, you can't just do that.

  • Funds are protected by various intellectual property laws, including trademarks.

  • Copyrights of design paintings.

  • Coffee into your own server may violate the policy of the right shoulder ballot concerned, but doesn't apply when you use Google phones All the phones.

  • Uncle, the funds are open sores and have permissive licenses, even just copy to your own server.

  • Disaster averted.

  • I, for one, will sleep tonight.

  • In fact, the CSF turns out to be so small that we might as well just in line it into our HTML all about these fonts.

  • Now the browser tries to be smart here when it comes to front downloading, it won't download fonts until it finds something on the page actually needs them.

  • That means it waits for the CSS to be loaded on, then an element appearing on in the dome that contains text that needs that font.

  • And this is good in some ways.

  • because it means the broad's gonna avoid downloading fronts it doesn't need.

  • But in this case, we know it needs both of those funds from the very start.

  • And the answer is a link rail pre low tag in the head off a document.

  • These tax basically allow you to tell the browser that it should download a thing and keep it a memory until it's actually being requested by the page.

  • And then it's already there.

  • And with those small changes, we should see the yellow line shrink when we pass it to weapons test the next time.

  • Oh, wow.

  • Let's go back.

  • Let's do it again.

  • Hey, don't run from canary figure slides.

  • I should know this by now.

  • Okay?

  • No deaths.

  • Yeah.

  • Yeah, I should have left.

  • Oh, so in theory, we should be saving.

  • They got a lot of time here.

  • Uh, right.

  • But we have to get it working in the build tools we have.

  • So this is the plug in we saw before the one that creates the HTML.

  • What we need to do is in line the CSS for our fonts, and we need to add a pre load tag for each of them now.

  • I'm not gonna go for it.

  • Step by step.

  • We've only got, like, three minutes or whatever, but it looks a little bit like this.

  • Woo.

  • There it goes.

  • At the start of the build, we use roll ups, admit effort method to bring the fund files into our bills.

  • And now roll up, is aware of these files, will add hash to the final name and put it into the output folder All the little things when it comes to generating our HTML, we pass that data into our temple it now so that we can where this helper will actually give us the final year l off the fund files.

  • Yes, That means we need to go back into our template.

  • And we need to look over that front data on output style tag that defines the font.

  • And this is just all the stuff we passed into the template before.

  • There's the wait, there's the source on.

  • Then we're gonna add a prototype for each of those as well.

  • So what I really like about this that the role a plugin handles all the role of specific stuff, like making it aware off the files putting them into the build pineapple and adding hashes, blah, blah, blah, blah.

  • But then, for the H.

  • Mel part, we use our HTML skills.

  • There's nothing specific to roll up about this templates.

  • Rollup isn't preventing us from rearranging or even adding new HTML tags toe our market.

  • But we are not done yet.

  • The front, certainly on the asset that is loading too late the same time like our main script loads and also will load the other script it needs.

  • So this is the code splitting thing we saw before because we're sharing scripts between the the main threat and workers.

  • They sit in different files.

  • Uh, but you know, we know once again that the main page will always need all three of these scripts, so we should be pre loading those as well.

  • Yeah, but the question is, what What faults should be pre loading.

  • We know there are dependencies.

  • What what are their actual names?

  • And luckily, the role of bundle object gives us the answer at a sad for each job is good pizza out, but that we have it will list give us an array of father being directly or statically imported So in this case, we pass that data into our tempered engine by just looking at the dot imports property and back over in our E.

  • J S Templar.

  • We can now just loop over these dependencies and generate a pre low tag for each of them, just like that s So we've now moved our fonts onto our own server.

  • We've added some pretty low tax for them and for our script as well.

  • Better in theory.

  • But what does webpage Tess tell us about the real world impact?

  • Well, we have eliminated the no funds friend of the second.

  • Anything is on screen, it's interactive and good to go.

  • And that's a one second improvement on three G and a massive three second improvement on to Gee, we haven't really impacted the red bar, though the time where the user sees absolutely nothing.

  • Yeah, and four seconds.

  • That's a lot of nothing.

  • Eight seconds is a lot, A lot of nothing.

  • This is the part where the user is just staring at a white screen.

  • They don't even know if the server is even think about sending them a response.

  • So looking at leverage tests, network waterfall confirms that we achieved what we set out to do.

  • Everything that's important.

  • It's now loading in parallel.

  • It's just taking too long.

  • Yes, we have two options here, like we can have a try and make this just shorter by shipping less code.

  • Or we could just make it matter less.

  • So right now we're fully reliant on Java strips to put anything on the screen.

  • So let's put a stop to that.

  • Let's use server site rendering.

  • But Bill time and that's often called a pre Orender or aesthetic render.

  • Yeah, so we want you to see something like this.

  • It's not interactive at this stage, so we've removed all of the buttons that depend on JavaScript.

  • But this can appear while the Java script is loading, and it's really improves the perception of performance because the user sees that something is happening.

  • And then once the job script loads lazily enhance the page on, there are a few ways to actually do this.

  • Every dorm orchestration framework that is worth talking about has a way to generate an HTML string from its components and in pre act and react land that is called rendered to string.

  • This is pretty fast.

  • It's not as fast as a general purpose template ing engine, but pretty close to the point where, actually, some people do run this on every request, although we only won't use a bill time.

  • So super high performance.

  • It's not as big of a requirement for us in this particular use case, however, render to string runs and no, and we actually see that as kind of a down side because if you have any codes in your components that assumes to be running in the browser, which usually is a fair assumption to make that will break and note.

  • So we had a component with index TB, and that would just break.

  • We could fix that by adding like coat branches for note versus browser, but that will get really messy over time.

  • Overalls ready to string is probably ideal if you can bend your components that way.

  • It's not what we ended up using.

  • The know we looked at J Storm, which is kind of like a browser environment, but it runs inside.

  • Note the problem.

  • There is the word kind of like just, um, is like an entirely new browser that you end up having to support, and we try to use it.

  • This is what we thought we were going to set along.

  • But then we hit all these kind of weird quirks like a CZ part of our in lining process.

  • We had some inline styles.

  • Andi Resource.

  • Some of those just going missing Andi.

  • It turns out that just on doesn't understand Linnea ingredients, so it's just getting rid of them on this is the right thing for it to do.

  • This is what the specs says, Suspect says.

  • If there's an inline style, you don't understand it.

  • Just just discard it.

  • Andi just on was dutifully behaving like a browser.

  • According to that speck, just it was a browser doesn't understand.

  • Linear ingredients on also, for its wealth is slower than render to string.

  • So it's not something you would want to be running on every request mint.

  • So in the end we ended up with a puppeteer.

  • Puppeteer launches a headless version off thrown that you get to remote control.

  • You can load pages, you can inject Java script.

  • You can inspect the Dominique and read back any results.

  • Eso your code is running in an actual chrome so you don't have to.

  • It's not a new browser for you to support.

  • It is, however, obviously slower than running to string.

  • It is also slower than Jack Stone, but actually surprisingly only by a tiny bid, but sadly only to run it once per build.

  • So it's not really that big a deal.

  • It is really easy to install to you.

  • So if you haven't done that yet, take a look at it and tell us what you think.

  • But let's be honest.

  • Adding an entire chrome to your built it up is a pretty big jump in complexity.

  • It is what we ended up doing for proximal, and it wasn't about yeah, so how do we get it working?

  • Well, we wrote another plugin.

  • Didn't we hear?

  • It is not gonna go through it line by line, just want to show you It's a relatively small chunk of code puppeteer.

  • Let's has launched this invisible version of chrome.

  • We run our JavaScript and we collect the HTML that it generates a za nice bonus.

  • Like since I see SS was inside our javascript, it was creating style tax for all of the components that were used in that first render.

  • So we sort of got CS in lining just for free.

  • So one day we haven't covered is how do we prevent the pre rendered from rendering components that aren't interactive yet.

  • So we want this landing stream to actually look a bit more like this.

  • Yeah, s o the simple solution to get that is you give a little bit of code to puppeteer just before we hand it the rest of our script.

  • And that means in our app, we can branch on that in an if statement and do stuff like high buttons.

  • You rearrange things and whatever.

  • And since that is only gonna be true in puppeteer land, it won't run those steps for real users.

  • But it does mean that you're a shipping code to really use us that they don't actually need.

  • But then again, it's probably not a lot off cold, and it's probably not worth putting in the effort to strip it all out.

  • Can we fix this?

  • Please help me fix this.

  • All right, let's let our aim is to remove this kind of kowtow ever reaching the production bundle and it's being shipped to use us.

  • Here's our current set of plug ins.

  • Can you guess what we're going to do now?

  • I don't know, but I'm excited about it.

  • We are going to write a plugging away.

  • Plugging means that we can write code like this.

  • And the value off this pre Renda will be exactly what the value of pre rendered in our roll up conflict script is.

  • Yeah, looking like this is great for all kinds of constants, like passing in late version.

  • Numbers of feelings are different kinds of flags, and I've seen similar plug ins that do this.

  • They don't require the import statement.

  • They just go through your code and replace a variable of a given name with a particular value.

  • But I don't know, I kind of hate that, because to me, it's not obvious from the source code that some build magic is going to happen.

  • Where is like here?

  • You look at that and you go Well, this import is not normal.

  • This is not how imports normally look s o.

  • You do a quick code search for, like, the star of that string, the constant cooling bit.

  • And then you'll find the building that's actually doing that.

  • It's really easy to discover on Also roll if it's really smart here.

  • So if you do a build where freeload it's true, it will actually optimize it to this on.

  • If you do a build where it is false, it will optimize it to this.

  • And so that's what we did.

  • We created two bills, one for the user and one for puppeteer.

  • So let's take a look at this.

  • Is legit.

  • The entire plug in the plug in on Lee does anything when the import statement starts with Constance Cola.

  • And if it does, it just generates the string off Java script on the fly containing the value that is being imported.

  • That's it, that's all.

  • Yeah, um, here is the comparable *** plug in that does the same thing.

  • If you want to have the dead code elimination again, it's not something I would feel comfortable hacking around with.

  • You might feel like we're, you know, kicking where pack a lot.

  • Here.

  • Uh, you were right.

  • We are.

  • But the honest truth is like the difference that we felt between working on a project with Web pack and working on a project Rollup was really really night and day for us.

  • Not only did we feel like we understood what was happening, we felt capable of changing what was happening if we needed to.

  • Especially with less Jordan past.

  • Like, you know, making workers a core part of the architecture.

  • It was incredibly valuable to be able to go in and just change how rollup handled these kind of things.

  • Okay, now we have an up to my serve.

  • Orender.

  • What do we win?

  • What is the real world impact?

  • Let's take a look, eh?

  • So we have pushed that read nothing rendered time right back.

  • We've put it almost two seconds of white screen on three G.

  • We've cut it by three seconds on to G.

  • This is a massive improvement to the perception of performance.

  • Yes, of the yellow every represents what?

  • We have something on screen.

  • But the app isn't really interactive yet because the Java script hasn't loaded.

  • But at least the user is seeing something to feel like they're being informed about the progress off the app loading.

  • So what can we do next?

  • Well, looking at the network waterfall to remind you that thin block is the setting of a connection and the stick block is the time it takes for the request and the response to go with the wire.

  • But there is another feature of network waterfalls that we can look at here, and that's the time to first bite.

  • Now both webpage test and chrome dentals.

  • They highlight the area before the first bite of the responses received.

  • So this is the time taken up by the request on waiting for the server to start sending the response.

  • And as you can see, there is a pretty big gap between receiving all of the HTML and receiving the first bite off any off the resource is used in the HTML.

  • It's about 400 milliseconds on three G and about a second on to D.

  • There are two solutions to this one is a C P to seven.

  • Push no.

  • So actually pushed turned out to be incredibly difficult to get right.

  • We have seen a couple of teams with a good number off, like networking experts try to use this, and they struggle to just break even in terms of performance.

  • Yeah, So the alternative then, is in lining like we take these assets and we just put them straight into our HTML.

  • So first up, let's do that with our funds in lining both our phones would add about 20 kilobytes to our HDL, which honestly, is kind of a lot.

  • Yeah.

  • So I took a look inside these files and I found some interesting stuff.

  • 3/4 on, upside down question mark and indecisive vowel, The surprised face.

  • No one knows what this is that set.

  • So what?

  • It's the next step.

  • No one knows what this is.

  • If you want a P and A B at the same time it's got You saw it on Dhe.

  • This, which looks like a rotated elephants.

  • I think that's what that is for.

  • The point is that none of these characters are in this set, which is the set of characters that were actually using on our landing page.

  • So we figured we'd just in line the characters that we actually need.

  • Which of these characters?

  • And that's you know, it's kind of like tree shaking, but for funds and for funds, it's called sub setting, and there are command line tools that do this for you, but they're written in python in a kind of loath python python a little on feature about the funds.

  • The your L for the C s s off your phone actually takes a parameter, which looks like this was the first language I love.

  • I know.

  • Move on here.

  • If you include this text parameter, the CSS will contain a your all to a new fund file which, specifically generate just contain the characters that you're using in this text parameter.

  • I still love python anyway, eh?

  • So we used build script to go into these files we generated and open them and spit them into our template as base 64 year olds.

  • And this only added 4.5 K to the HTML, which is much better than the 20 k for the full fronts.

  • We do still load the full funds because the future screens will have more than just that initial set of characters.

  • But, you know, they're an interactive to your way, so we can wait for, like, you know, unload those lazily in the background.

  • So how do we do this?

  • Well, back to our create HTML plug in, or at least the part of feats data into our template ing engine for each fund were pacing in the weight and your l but you're also going to pass in the inline fund as a base.

  • 64 encoded strength.

  • Yeah, this is just using built in no day p.

  • I is nothing special, but we're also going to pass in the Unicode range for each font.

  • Now, if you've used weapons before you have seen that you need to specify Unicode range to tell the browser exactly what's inside the front.

  • There.

  • We use this little library from NPM, which just takes a lot of characters on.

  • We'll give you a valid CSS Unicode range for all of those.

  • So now we're passing everything into the template that we need to get the phone.

  • But what about our Java script?

  • Yeah, So here's what we're getting the file name, uh, you know that we're passing into the template, but rollup instead could just give us the entire code job done.

  • We're also passing in the file names for all the dependencies we talked about earlier.

  • Eso Instead, we'll map over those and return the code for those instead.

  • So we had to change the occasional templates.

  • A result.

  • Handle that.

  • But again, this is using our skills and HTML nothing.

  • Plug in specific.

  • So here's where we're doing The online front There is part of the base 64 year L.

  • We can add the Unicode range there, and there is the inline script, so we're done in theory.

  • But how does this impact our real world performance?

  • We've already improved things a lot, but with in lining we've reduced our interactive time by half a second on three D and by about a second onto JI.

  • But we're not done yet.

  • Now this job script is inclined as well.

  • We've reached the point where the only thing that matters for First Interactive is everything that's inside of the HTML files.

  • We've come a long way, so even over to G, we're now interactive in just under six seconds.

  • Not too bad, but we could do about yeah, like looking are at our HTML file or Index HMO fall.

  • It's 43 kilobytes and 32 kilobytes off that are Java script, and that is the code for everything.

  • But it's all the fancy animations.

  • It's our rendering engines.

  • The Web gel bits.

  • It's the end screen, and the use of duty doesn't need the end screen at the start of the game.

  • Yeah.

  • What we've done here is we've We've done a photo shop, right?

  • Do you have experiences before you're staring at this screen while it loads like 100 plug ins?

  • Even though, like the first interaction, all you can really do when it when it starts up is creating new image or load an existing image.

  • You don't need all of those plugs until sometime.

  • Like Iran.

  • Yeah.

  • My, my my favorite plug in is her leader.

  • Bottlenecks like serious.

  • When you first showed me this, I fought like, well, ironically, I thought you'd photo shop just a silly name in there like a punk I wasn't getting.

  • This is a really it's a real pleasure.

  • This is I love this.

  • It sounds like a Swedish folk singer like Highlight the Bottlenecks I Yeah, so let's not load everything before the user can do anything.

  • Let's prioritize the code to do this.

  • The first interaction is basically the usual picking what kindof game they want to play, and the only thing read to react to is the user hitting the start button.

  • And if for some reason, the user manages to press the start button before our A game Logic has loaded.

  • That's when we can spend up loading screen.

  • Everything else can really just lower Second later, it won't really matter.

  • Yes, so this is where we need to code split at this point because this is our first interactive bit.

  • We don't have the fancy animated background or the logo that you know.

  • That stuff is non essential, really.

  • Coast Letting in rollup works much the same as it does in Web Kit and Web pack and parcel imports like this.

  • This will cause whatever dot Js to be bundled into the same file.

  • If you want to be called split instead, you'll use a dynamic import, and this will return a promise.

  • So if you want to use that module sometimes later you will have to await it just in the usual way.

  • So the difference now is that whatever did Jess is not gonna be bundled in, is going to be put into another chunk, and that makes it a sink, which can bring its own problems.

  • For example, most off the U I framework that we're using nowadays expect rendering to be synchronised and can't really handle promises.

  • So react suspense is aiming to change that by allowing you to lazy lode components.

  • But pre act doesn't have suspense.

  • So off course rewrote it ourselves in 20 lines.

  • It obviously it can all half off the things off that react suspense can do.

  • But it can do everything that we needed that we needed to do so really what it does if you give it a promise off a component, it wrapped it and return to a real components synchronously.

  • And you can use that component as a placeholder with two parameters basically will take a loading function, which will reputable, used for running a placeholder until the underlying components ready and at that point just switches over and uses the other function.

  • Like for a nebula.

  • Yes, s.

  • So with that, we moved all of our components to a lazy model except the ones that we needed for the first render on this cough over 20 K off the html that the job script is now down to just 11 k now, I mean, honestly, I think 11 cases a lot of javascript for what is basically just a simple form on a button but, you know, it's done its job.

  • It's given us like that really quick.

  • First bit too interactivity.

  • But you know, you're gonna develop this happy gonna add stuff.

  • Fixed bugs.

  • How do we stop this creeping up over time?

  • And this turned out to be quite hard.

  • Quite interesting.

  • So you know, you're sitting there, you're writing new component.

  • You want to add a new feature to the app, and you do everything right.

  • You think about performance, you think about file size on it's Friday afternoon.

  • And none of your colleagues are looking on dhe and you have a week moment, and then you do it.

  • You use V s Code Auto Complete and Bam.

  • Suddenly you have said it imported pulls in 200 K off more code.

  • And that that exactly it's how Microsoft mind sweeper happens.

  • Yeah.

  • So we tried to think about how is ways we could fix this.

  • We tried the comment system where we just put a warning in files that Richard stealing code to Yeah, bulletproof isn't it did help a little bit.

  • It was acted as a reminder.

  • It was something we look at in defense.

  • But yes, it wasn't the best solution tools, not rules s so we felt a little thing.

  • This hooks up to Travis, see eye.

  • And so on each build, it will go and look at everything in the dist folder, and it will record the sizes of it.

  • And that means when you create a PR, it will compare that against master.

  • So it'll give us the delta for all of the files.

  • And so that means for every PR, we just go into this.

  • We have a look and you will be able to see if the index html file is ballooning in a way that we didn't expect this This works for all projects that use Travis, so feel free to give it a go.

  • So what do we win?

  • What do we gain?

  • Since this is our last optimization?

  • Let's rewind all the way back to the start to see where we started.

  • Yeah, we started, like, five seconds until ready on three G and 11 seconds.

  • Already on to Ji, we moved the fonts into our own servant.

  • We pre loaded the fonts and the scripts and that improved the time to interactive.

  • We added a setting render improving perceived loading performance and getting pixels on the screen earlier.

  • And then we enlighten our scripts and subsided the fonts, bringing down the time to interactive again.

  • And then we split the cold.

  • We focus on the coat, would be needed for interactivity and split off everything else.

  • And that slash the time to interactive by over a second on three G and by two seconds onto GI.

  • Yes, I'm from the starting point.

  • We've like half the time to interactive, and so let's actually feel what that difference is.

  • So here on the left is the original Alfa version.

  • On the right is the latest version This is loading over to G Connection.

  • So we still got a bit of a delay at the start, setting up connections, but then are optimized version.

  • There it is, and now it's interactive.

  • The user comm use it.

  • The old version gets there.

  • But come on, it's like still not interactive cause of the fonts.

  • And finally, it's like so much later.

  • And remember, when you are at a festival on a train on conference like here, or you just on vacation and using roaming, you will be experiencing speech that speeds that closer to three g or even to G sometimes.

  • Yeah, And I also want they're playing the game.

  • We install the service worker because, you know, I'm not allowed to ship anything that doesn't have a service worker on that means like it's gonna work off line first.

  • But, you know, as a side effect, it means it cuts down the timing to like, Well, pretty much instantly.

  • Just a second for old cash is displaying.

  • So you might be wondering, where did we end up with our plug encounter?

  • Well, to be ho

wear anxiously waiting.

字幕與單字

單字即點即查 點擊單字可以查詢單字解釋

B1 中級

在構建工具的世界裡快速地做事情,由Surma和Jake Archibald主持|JSConf Budapest 2019 (Making things fast in world of build tools by Surma & Jake Archibald | JSConf Budapest 2019)

  • 0 0
    林宜悉 發佈於 2021 年 01 月 14 日
影片單字