Skip to content

perf(weapp-tailwindcss): 优化多构建器热路径缓存复用#819

Open
sonofmagic wants to merge 129 commits intomainfrom
perf/weapp-tailwindcss-hotpath-caching
Open

perf(weapp-tailwindcss): 优化多构建器热路径缓存复用#819
sonofmagic wants to merge 129 commits intomainfrom
perf/weapp-tailwindcss-hotpath-caching

Conversation

@sonofmagic
Copy link
Owner

@sonofmagic sonofmagic commented Mar 10, 2026

变更说明

  • 优化 Vite bundle 增量状态与 CSS/HTML 热路径的缓存复用
  • 优化 core、gulp、webpack、uni-app-x 的默认 handler options 复用,减少重复对象构造
  • 优化 JS literal 处理、runtime/cache、compiler context cache 与 lightningcss 固定成本
  • 补充 bundler、core、context、runtime、lightningcss 的回归测试

验证

  • pnpm exec vitest run test/bundlers/vite-bundle-state.unit.test.ts test/bundlers/vite-plugin.bundle.unit.test.ts test/bundlers/vite-plugin.incremental-issue-33.test.ts --config ./vitest.config.ts
  • pnpm exec vitest run test/bundlers/vite-plugin.uni-app-x.unit.test.ts --config ./vitest.config.ts
  • pnpm exec vitest run test/js/handlers-branches.test.ts test/js/handlers-stale-fallback-regression.test.ts test/js/framework-dynamic-class-regression.test.ts test/js/index-handler.test.ts test/bundlers/vite-plugin.incremental-issue-33.test.ts --config ./vitest.config.ts
  • pnpm exec vitest run test/context-cache.test.ts test/context/index.test.ts test/context/refresh.test.ts --config ./vitest.config.ts
  • pnpm exec vitest run test/tailwindcss/runtime-cache.test.ts test/tailwindcss/runtime-hot-update.test.ts test/tailwindcss/runtime.test.ts test/bundlers/vite-plugin.bundle.unit.test.ts --config ./vitest.config.ts
  • pnpm exec vitest run test/lightningcss/style-handler.test.ts test/core.test.ts test/postcss/style.test.ts --config ./vitest.config.ts
  • pnpm exec vitest run test/bundlers/gulp.unit.test.ts test/bundlers/vite-plugin.bundle.unit.test.ts test/bundlers/webpack.v5.unit.test.ts test/bundlers/webpack.v4.unit.test.ts --config ./vitest.config.ts
  • pnpm exec vitest run test/core.transform-wxss-options.unit.test.ts test/core.test.ts --config ./vitest.config.ts
  • pnpm exec vitest run test/bundlers/gulp.unit.test.ts test/bundlers/vite-plugin.uni-app-x.unit.test.ts test/bundlers/webpack.v5.unit.test.ts test/bundlers/webpack.v4.unit.test.ts --config ./vitest.config.ts
  • pnpm exec vitest bench test/core.bench.ts --config ./vitest.config.ts

Summary by Sourcery

改进热路径缓存以及在各打包器和核心转换中的默认处理器选项复用,以减少增量构建中的重复计算。

Enhancements:

  • 优化 Vite 打包构建状态跟踪和依赖映射,更好地在增量运行中复用 JS/CSS/HTML 处理结果。
  • 在 core、gulp、webpack、Vite 和 uni-app-x 集成中缓存并复用默认的 style/template/js 处理器选项,避免为每个资源或构建重新构造 override 对象。
  • 优化 JS 字面量类名转换,在同一个字面量内复用解析结果,减少重复的转义操作。
  • 调整编译器上下文缓存键策略,将基于稳定选项的上下文与运行时作用域探测分离,同时避免不必要的调用方位置检查。
  • 当 override 选项为空时复用 lightningcss 的预处理工作,以尽量降低每次调用的固定开销。
  • 通过在单个事件循环周期内缓存运行时配置签名并在配置变更时精确失效,限制 Tailwind 配置的 stat 调用次数。

Tests:

  • 添加 Vite 的打包状态单元测试,以验证增量依赖跟踪和关联入口失效逻辑。
  • 扩展 core、gulp、webpack、Vite、uni-app-x、lightningcss、JS 处理器、上下文缓存以及运行时缓存的测试,以覆盖处理器选项复用、运行时变更和签名缓存行为。
Original summary in English

Summary by Sourcery

Improve hot-path caching and default handler option reuse across bundlers and core transforms to reduce repeated computation in incremental builds.

Enhancements:

  • Refine Vite bundle build state tracking and dependency mapping to better reuse JS/CSS/HTML processing across incremental runs.
  • Cache and reuse default style/template/js handler options in core, gulp, webpack, Vite, and uni-app-x integrations to avoid reconstructing override objects per asset or build.
  • Optimize JS literal class name transformation to reuse resolution results within a literal and reduce redundant escaping work.
  • Adjust compiler context cache keying to separate stable option-based contexts from runtime scope probes while avoiding unnecessary caller-location inspection.
  • Reuse lightningcss preparation work when override options are empty to minimize fixed per-call overhead.
  • Limit Tailwind config stat calls by caching runtime config signatures within an event loop turn and invalidating precisely on config changes.

Tests:

  • Add bundle state unit tests for Vite to validate incremental dependency tracking and linked entry invalidation.
  • Extend core, gulp, webpack, Vite, uni-app-x, lightningcss, JS handler, context cache, and runtime cache tests to cover handler option reuse, runtime changes, and signature caching behaviors.

@changeset-bot

This comment was marked as resolved.

@sourcery-ai

This comment was marked as outdated.

sourcery-ai[bot]

This comment was marked as resolved.

@sonarqubecloud
Copy link

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