feat: openclaw gateway 启动速度优化 (esbuild bundle + compile cache + 插件预编译)#395
Merged
btc69m979y-dotcom merged 8 commits intofeature/openclawfrom Mar 12, 2026
Merged
Conversation
在 Electron utilityProcess 中,openclaw 的 ~1100 个 ESM 模块解析极慢 (80-100s)。通过 esbuild 将 dist/entry.js 打包为单文件 gateway-bundle.mjs, 使用 import() 动态加载,消除模块解析开销。 主要改动: - 新增 scripts/bundle-openclaw-gateway.cjs: esbuild 打包脚本,带缓存检查 - package.json: 添加 openclaw:bundle 步骤到所有平台构建链 - openclawEngineManager.ts: launcher 优先 import(bundle),失败回退到 require(dist/entry.js) - 添加 esbuild devDependency - launcher 中 argv[1] patch 确保 isMainModule() 识别 bundle 为主入口 - banner 注入 createRequire 解决 ESM 上下文中 CJS 模块的 require() 问题 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- 新增 scripts/patches/openclaw-gateway-entry.patch: 为 openclaw 添加专用 gateway 入口(gateway-entry.ts), 跳过 Commander CLI 基础设施,冷启动从 156s 降至 95s - 新增 scripts/apply-openclaw-patches.cjs: 自动化 patch 应用脚本,幂等执行,已应用则跳过 - 构建链中插入 openclaw:patch 步骤(ensure → patch → build) - build-openclaw-runtime.sh 增加 patchHash 指纹, patch 文件变更时自动触发重新构建 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Enable V8 compile cache for the openclaw gateway to eliminate cold-start V8 compilation overhead (~35s for the 26MB bundle). Changes: - Set NODE_COMPILE_CACHE env var in utilityProcess.fork() for ESM support - Add enableCompileCache() + flushCompileCache() in gateway-launcher.cjs - Add warmup-compile-cache.cjs script for pre-populating the cache - Add NSIS post-install hook to run warmup during Windows installation - Copy warmup script to runtime dir during bundle step The compile cache is stored at <userData>/openclaw/state/.compile-cache and persists across app restarts. On Windows NSIS install, the warmup runs automatically after file extraction using ELECTRON_RUN_AS_NODE=1. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
On Windows, @electron/asar listPackage() returns backslash-separated paths (e.g. \dist\entry.js) but the validation code checks for forward-slash paths (/dist/entry.js). Normalize to forward slashes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
On a fresh install with no API model configured, syncOpenClawConfig() would bail out entirely, leaving no openclaw.json file. Without this file the gateway has no gateway.mode=local and exits silently. Now writes a minimal config with gateway.mode=local and plugin entries so the gateway can start immediately. The full config (with model provider) is synced once the user configures an API in the UI. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove plugins from minimal openclaw config so gateway can bind port immediately on fresh install (plugins loaded via jiti were blocking httpServer.listen for minutes) - Protect existing configs with IM plugin settings from being overwritten by minimal config on sync - Show file extraction details in NSIS installer while hiding warmup operations from progress text - Fix apply-openclaw-patches idempotent detection for patches containing new files Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add scripts/precompile-openclaw-extensions.cjs that uses esbuild to compile each extension's TypeScript entry point to JavaScript at build time. This eliminates jiti's runtime Babel transpilation (~135s on first Windows startup reduced to ~82s). Extensions already shipping as .js (feishu-openclaw-plugin, wecom-openclaw-plugin) are skipped. Also: - Add install timing log to NSIS installer for diagnosing slow installs - Hide empty details list (ShowInstDetails nevershow) since electron-builder uses 7z solid extraction with no per-file output - Integrate precompile step into all openclaw:runtime:* build scripts Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…claw-gateway-esbuild-bundle # Conflicts: # package.json
This was referenced Mar 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
优化 openclaw gateway 在 Windows Electron utilityProcess 中的启动速度,从 180s+ 超时 降至 ~85s(首次)/ ~15s(后续)。
核心改动:
gateway-bundle.mjs,消除 ESM 模块图解析开销(1100+ 文件 → 单文件,启动从 ~100s 降至 ~4s)runGatewayCommand改动文件
scripts/bundle-openclaw-gateway.cjsscripts/precompile-openclaw-extensions.cjsscripts/warmup-compile-cache.cjsscripts/apply-openclaw-patches.cjsscripts/patches/openclaw-gateway-entry.patchscripts/build-openclaw-runtime.shscripts/nsis-installer.nshscripts/electron-builder-hooks.cjssrc/main/libs/openclawEngineManager.tssrc/main/libs/openclawConfigSync.tspackage.jsonTest plan
🤖 Generated with Claude Code