Rolldown 如何工作:使用 Bitset 逻辑的高性能代码分割

Rolldown is a high-performance JavaScript bundler that Vite plans to integrate as its future default. The bunlding process consists of three major stages: module scanning, symbol linking, and final code generation. I have already written two articles detailing the first two stages, which you can find here:

Rolldown 是一个高性能的 JavaScript 打包器,Vite 计划将其集成为其未来的默认选项。打包过程包括三个主要阶段:模块扫描、符号链接和最终代码生成。我已经写了兩篇文章详细说明前两个阶段,你可以在这里找到:

With those stages complete, we now have a precise "map" of the project — ranging from high-level module graphs to underlying symbol relationships. In this final stage, we leverage this information to generate the actually bundled output. This is the stage that directly impacts your application's loading speend and bundle size.

那些阶段完成后,我们现在拥有项目的精确“地图”——从高层模块图到底层符号关系。在这个最终阶段,我们利用这些信息生成实际的打包输出。这是直接影响您的应用程序加载速度和 bundle 大小的阶段。

Code generation strategies

代码生成策略

Rolldown utilizes two primary strategies for code generation: Preserve mode and Normal mode. In Preserve mode, the bundler creates separate chunks for every module, maintaining the original module names as filenames. This is a relatively straightforward 1-to-1 mapping often used for library distribution. In contrast, Normal mode is where the core complexity lies; here, Rolldown transforms the module graph into a series of optimized chunks, merged chunks.

Rolldown 使用两种主要的代码生成策略:Preserve modeNormal mode。在 Preserve mode 中,打包器为每个模块创建单独的 chunks,保持原始模块名称作为文件名。这是一种相对直接的 1-to-1 映射,常用于库分发。相比之下,Normal mode 是核心复杂性所在;在这里,Rolldown 将模块图转换为一系列优化的 chunks、合并的 chunks。

This article will focus primarily on the code splitting algorithm that drives this high-performance generation. To wrap up, we will explore the post-processing phase, where Rolldown applies final structural optimizations to the output.

本文将主要关注驱动这种高性能生成的代码拆分算法。最后,我们将探讨后处理阶段,在那里 Rolldown 对输出应用最终的结构优化。

Generate chunks

生成 chunks

This section focuses on the core logic of the chunk generation stage. Since the full generation process involves many moving parts — such as handling namespaces, chunk linking, and w...

开通本站会员,查看完整译文。

首页 - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.0. UTC+08:00, 2026-03-06 17:25
浙ICP备14020137号-1 $访客地图$