Currently, Next.js is using four to five Webpack compilers to make all this work, one for client, for server rendering, for edge rendering, for several components, and a fallback compiler for error messages. All this kind of light orchestration work between these compilers is not that easy. It's kind of working, but it's a source of errors, where you can make mistakes or forget something, or the communication is not working correctly, and that's not something we want to be forced to.
So, there are also some challenges on the WEPAC side, so WEPAC was built ten years ago, and it still has the architecture from ten years ago where applications were like hundreds of modules, and web development scaled a lot in the last decade, and, yes, so WEPAC architecture was not really built for this kind of large-scale incremental build performance kind of thing. That is a problem, and we can't easily fix that because there are a lot of plugins that depend on the architecture of WEPAC, and it's really hard to make backwards-compatible changes to the architecture, we can't really change the architecture while being backwards-compatible. We don't want to break everyone's use cases by changing the architecture of WEPAC, so that's not really a good opportunity to fix that.
On the other hand, we fixed a lot of things while I'm working on Next.js in WEPAC to make it more performant, but we had a limit on the kind of optimisation we can do without rewriting everything. There are also some other challenges like cache invalidation. In many cases it's either too sensitive, so like you change something and it affects, it has to rebuild a larger part of the application, while it's probably not affected. In an example, if you change a comment, why do we have to rebuild the module? It could be more granular in what we can cache. One problem of the architecture is this cache, lookup, cost problem. What we do when doing an incremental build is we basically start similar to a full build, start building it, and for every work we want to do we first check if it's in the cache, if it's already cached, and then we can skip doing that work, and that sounds great, but on that scale, if you look up, like, 10,000 modules of modules in the cache, then you have this serious cost of looking things up in the cache, and, yes, that's kind of a problem.
But, yes, we are talking about lookup problems like when you're talking about a few seconds of rebuild. If you work in the native world, you might know that they are incremental times of minutes or something like that. Yes, we have a really luxurious problem in the web development world, I guess! But there were also some opportunities that we could address while working on a new Bundler. So at best, we have this tool called TurboRepo, and when combining this with Next.js, we can a lot of stuff from each other. Next.js has this cool granular caching, like if you change one module you only rebuild one module and some boilerplate stuff. But in the TurboRepo tool, you always have this caching granularity of whole commands. And then TurboRepo can learn from Next.js by having more granular caching, but also can learn by having more of a development-focused watch mode where you can have this kind of incrementality-watch-thing experience by default. But on the other side, Next.js can learn from TurboRepo. TurboRepo has this cool feature about remote caching, so it can actually share your cache with your team and it's uploaded to the cloud or it is a self-hosted solution. And then you can share that with your team and you don't have to rebuild what your colleagues has had built. That's cool. We wanted to have that in Next.js, like sharing cache with team and sharing cache with deployment so you don't have to do the whole work twice. But there are some new opportunities. I've seen that many developers actually want to have more insight into the build process. What's the size of the page of components, what's the size of dependencies and how does pull requests affect the change of my application or performance change of my application. This kind of insights. And we want to offer more of these types. Also related to build performance, meta statistics, why is my build slow or how does this affect my build time, these kinds of statistics.
Comments