目录

moonshrink — MoonBit Wasm 体积分析工具

面向 MoonBit 编译产物的 Wasm 二进制体积分析工具。直接解析 .wasm 文件,统计 section、函数、符号、包维度的体积分布,支持终端表格、JSON、CSV、Markdown、treemap 和版本对比。

构建与运行

开发测试(无需 C toolchain)

moon test

Native 编译

需要 C 编译器(Windows: Visual Studio Build Tools + Windows SDK 或 tcc)。

moon build --target native
moon run --target native cmd/main -- sections target.wasm

目标兼容说明

  • wasm-gc: moon test 默认目标,沙箱无文件 I/O,read_file 返回桩错误。
  • native/llvm: 完整文件 I/O + exit code,依赖 C 标准库。

CLI 使用

moonshrink target.wasm --top 30 --format json
moonshrink sections target.wasm
moonshrink symbols target.wasm
moonshrink treemap target.wasm -o treemap.json
moonshrink diff old.wasm new.wasm --top 30

退出码

含义
0 成功
1 解析 / IO 错误
2 参数错误

测试 fixtures

testdata/wasm/ 包含 6 个 wasm 文件:

文件 大小 说明
minimal.wasm 8 B 最小合法 wasm
simple.wasm 11 B 含空 custom section
named.wasm 69 B type/import/function/code/name/export 六 section
moonbit_sample.wasm 349 KB MoonBit 编译产物(analysis 测试)
stripped.wasm 484 KB MoonBit 编译产物(wasm 测试)
malformed/*.wasm <12 B bad magic / 截断 section

项目规模

测试数 模块数
core 44 5
wasm 328 15
symbols 233 7
analysis 197 8
output 184 10
diff 24 6
cmd/main 107 9
io - 3
合计 1441 63
关于
1.9 MB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9 京公网安备 11010802047560号