Check out a free preview of the full JavaScript Performance course
The "Prepack" Lesson is part of the full, JavaScript Performance course featured in this preview video. Here's what you'd learn in this lesson:
Prepack is an experimental library for reducing the computing needed to execute JavaScript.
Transcript from the "Prepack" Lesson
[00:00:00]
>> Steve Kinney: There's one other one that's kind of experimental that I wanna talk about. And it's the idea called prepack. And so prepack, I mean, I can, you know, I'm a teen. It says a tool for making Java's code run faster. Emphasis on the word run. It might not always make your code smaller.
[00:00:16]
But it's that kind of interesting in my project. It's definitely not ready for production but it's interesting to play around with. And so, here's a loop but this loop starts at 0, goes to 10 and does a thing. And so what happens is the parser parses this loop, compiles it out like re-run through it but effectively what happens is this.
[00:00:37]
So, a prepack does is that it takes this and at build time turns it into this so the browser never has to do it. Right, it does all of those things that gonna happen anyway immediately. But like, this code is shorter than this code, right? So there's some trade offs there.
[00:00:52]
But sometimes you can do some interesting things like here's a Fibonacci sequence. And you can see if you put it in prepack, it executes it in time. And just spits out the result. So now the browser will never go through this Fibonacci sequence. It's just gonna spit out 55 cuz that's what was gonna come out anyway.
[00:01:13]
There's no point making you users do it. Definitely experimental tool but kind of interesting. I showed more to like frame the way you think about. Like what do we do it on our computers at build time whether we ship it out to our users to do it. That's the main goal like I, I don't use this.
[00:01:28]
I don't think it's even recommended to be used at this point. But I think it's an interesting idea for framing the way we think about do we do time. Or do we ship it to users for them to do at their compile time? We can get a lot of winds on our user side by figuring out interesting ways to do this at the one time that we ever have to build that asset.
[00:01:48]
And push it up to S3 or whatever.
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops