RFC: Replace AST-based Module Analysis with Sourcemap-based Analysis in Rsdoctor #1253
yifancong
started this conversation in
RFC & Project Optimize
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
This RFC proposes replacing Rsdoctor’s existing AST-based module analysis with a more efficient, accurate, and side-effect-free Source Map-based solution. The new approach aims to improve module size analysis, enable precise handling of concatenated modules, eliminate side effects from banner analysis, and provide support for CSS module analysis.
Motivation
Pain Points
The current AST-based analysis in Rsdoctor has several limitations:
Concatenated Module Analysis
Concatenated modules (modules merged into a single closure during bundling) cannot be decomposed accurately. As a result, Rsdoctor annotates them with a "Concatenated" label, making size attribution imprecise and increasing the user's cognitive load to understand this concept.
BannerPlugin Side Effects
Rsdoctor currently uses comment markers for BannerPlugin analysis, which introduces side effects into the bundle and prevents its use in CI/CD pipelines.
Lack of CSS Module Analysis
There is no logic to parse and analyze CSS modules, resulting in incomplete size analysis for CSS assets.
Glossary
mappings
field to compress position data.Plan
1. Read Bundle Content and Source Map
asset.source.sourceAndMap()
.2. Iterate Source Map Mappings and Group by Line
SourceMapConsumer
to parse the source map, decoding VLQ to getgeneratedColumn
,generatedLine
,originalColumn
, andoriginalLine
.3. Sort and Split Code Segments by Column
sourceMapSets
.4. Aggregate Code Segments per Module
source
field in each mapping indicates the real source module.sourceMapSets
map to assemble and aggregate code segments belonging to the same module.Seamless Source Map Support in Rspack
Rsdoctor’s native plugin utilizes
SourceMapDevToolPluginOptions
in Rspack, enabling concatenated module analysis even when users do not explicitly enable source maps. This ensures smooth integration and consistent analysis without additional user configuration.Acknowledgements
We drew inspiration from some of sonda’s implementation ideas. Sonda is a lightweight and user-friendly bundle analysis tool.
Beta Was this translation helpful? Give feedback.
All reactions