tz-lts
v0.1.0
Published
Analyze potential long tasks and generate patch to split heavy sync work into async chunks.
Readme
longtask-split (MVP)
独立 CLI:分析潜在长任务热点,并生成 patch(默认不写回文件)把同步重计算改造成可 await 的异步切片版本(Promise 化)。
安装与构建
cd tools/longtask-split
npm i
npm run build本地运行(构建后):
node dist/index.js --help命令
1) Analyze
node dist/index.js analyze <repoRoot> --file <path> --symbol <name>输出:
longtask-report.jsonlongtask-report.md
2) Transform (Patch only)
node dist/index.js transform <repoRoot> --file <path> --symbol <name> --patch longtask-split.patch可选注入 runtime(在 patch 里新增 TaskSplitter/yieldToMain 文件):
node dist/index.js transform <repoRoot> --file <path> --symbol <name> \
--inject-runtime \
--runtime-path src/utils/task-splitter.ts \
--patch longtask-split.patch行为边界(重要)
- 默认只新增
xxxAsync(Promise 化)并在其内部对第一处for (...)插入await yieldToMain('idle')作为示例切片点。 - 会尝试自动改造调用点(安全子集):
- async function 内:
foo()→await fooAsync() useEffect(() => { ... })且 无 cleanup return:把整个 effect body 包进 async IIFE 再执行
- async function 内:
- 不会改造 render/useMemo/useCallback 同步路径;会在 report 里提示原因。
- 不能中断“单个 task”;如果单次循环体本身很重,仍需要进一步拆小工作单元。
