Skip to content

perf(weapp-tailwindcss): optimize Tailwind v4 build and HMR hot paths#996

Merged
sonofmagic merged 5 commits into
mainfrom
codex/perf-v4-build-hmr
Jul 14, 2026
Merged

perf(weapp-tailwindcss): optimize Tailwind v4 build and HMR hot paths#996
sonofmagic merged 5 commits into
mainfrom
codex/perf-v4-build-hmr

Conversation

@sonofmagic

@sonofmagic sonofmagic commented Jul 14, 2026

Copy link
Copy Markdown
Owner

Summary

针对用户反馈的 Tailwind CSS v4 构建与 HMR 性能问题,补齐 Vite/Webpack 关键流程覆盖与阶段计时,优化已确认的候选更新和 Vite CSS 产物热点,并建立 PR 基线对比性能门禁。

Changes

  • 优化 source candidate 增量更新,避免单文件变化时复制和比较完整全局候选集合
  • 优化 Vite 已处理 CSS 注入后的源资产清理,只扫描 CSS 资产,并复用已解析的规则覆盖信息
  • 合并 root CSS 精确去重和 scoped Tailwind 全局规则清理,减少重复 PostCSS 解析与 AST 遍历
  • 保持无 root style asset 时 scoped Tailwind theme/preflight 的既有清理行为,并新增回归测试
  • 为 Vite generateBundle 和 Webpack processAssets 增加阶段级 timing details
  • benchmark 同时记录端到端 build/HMR 和插件处理耗时、样本数、p95 与原始 timing payload
  • 新增 pnpm perf:guard:PR 对比 base SHA,push/manual 保留 current-vs-published 趋势
  • 门禁阈值:插件阶段回退超过 10%;端到端回退超过 15% 且绝对增加超过 50ms
  • 插件 timing 样本缺失或不完整时直接判定门禁失败
  • PR 覆盖 weapp-vite、Taro Vite、Taro Webpack、uni-app Vite、Mpx 五个 Tailwind v4 场景
  • PR HMR 样本由 4 轮增加到 6 轮,并使用 dev ready 后的全部真实更新样本计算中位数
  • Mpx 端到端 watch 包含框架 rebuild/output flush 波动,仅作展示;processAssets 插件阶段仍执行 10% 门禁
  • 新增 source candidate、processed CSS coverage、processed CSS injection 三个核心微基准和中文 Changeset

Performance

GitHub Actions 基准:29318724562,对比 PR base 2372a3649;build 3 次、HMR 6 次,表中为中位数。Performance guard 通过,0 个违规项。

Framework HMR

场景 Base Current 变化
Taro Vite HMR 26.16s 8.96s -65.75%
Taro Vite plugin HMR 19.46s 4.63s -76.19%
Taro Webpack HMR 4.00s 4.18s +4.64%
Taro Webpack plugin HMR 1.95s 1.90s -2.81%
uni-app Vite HMR 1.33s 1.15s -13.67%
uni-app Vite plugin HMR 685.00ms 450.50ms -34.23%
Mpx HMR(informational) 7.01s 6.88s -1.74%
Mpx plugin HMR 2.73s 2.63s -3.75%
weapp-vite HMR 483.26ms 482.39ms -0.18%
weapp-vite plugin HMR 195.00ms 183.00ms -6.15%

Core Hot Paths

场景 Base Current 变化
source candidate hot update 201.55ms 12.96ms -93.57%
processed CSS coverage 200.98ms 115.56ms -42.50%
processed CSS injection 3.87s 1.46s -62.28%

Build 稳态中位数在五个框架上的平均变化为 -1.02%;插件 Build 平均变化为 -5.54%

Testing

  • pnpm --filter weapp-tailwindcss exec vitest run test/bundlers/vite-processed-css-assets.unit.test.ts test/ci/benchmark-report.test.ts test/ci/workflows.test.ts --pool=threads --maxWorkers=1
    • 81 tests passed
  • E2E_PROJECT_FILTER='^uni-app-vite-tailwindcss-v4$' pnpm exec vitest run -c ./e2e/vitest.e2e.config.ts e2e/apps-generator-mode-compare.test.ts -t 'builds retained demos'
    • uni-app generator 小程序、H5、App 输出快照通过,未更新基线
  • pnpm --filter weapp-tailwindcss build
  • benchmark production scripts ESLint and node --check
  • CI 29318724517 passed,包括 Quality、Compatibility、E2E Static、Focused、Multiplatform 与 Watch gates
  • Release Gate 29318724518 passed
  • Benchmark 29318724562 passed,五框架与三个 core 场景均无错误且 timing 样本完整

pnpm --filter weapp-tailwindcss test completed with 2815 passed and 10 snapshot indentation failures. These failures reproduce in the origin/main baseline; no unrelated snapshots were updated.

@changeset-bot

changeset-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b2f728f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
weapp-tailwindcss Patch
@weapp-tailwindcss/build-all Patch
@weapp-tailwindcss/website Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@sonofmagic sonofmagic merged commit 7adc184 into main Jul 14, 2026
64 of 67 checks passed
@sonofmagic sonofmagic mentioned this pull request Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant