openclaw - 💡(How to fix) Fix perf: subcommand --help takes 10-22 seconds due to eager jiti plugin compilation in pi-embedded [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#59135Fetched 2026-04-08 02:28:13
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Author
Participants

openclaw <subcommand> --help blocks for 10–22 seconds on every invocation. The root --help fast path (openclaw --help) works correctly at ~165ms. The regression affects all subcommands that trigger full program initialization: status, agent, secrets, gateway, sessions, tasks, etc.

Root Cause

Three interacting issues cause the slowdown:

  1. tryRouteCli() in run-main-Cv4tme_8.js (~line 290) bails out with if (hasHelpOrVersion(argv)) return false, forcing all subcommand --help invocations through full program initialization.

  2. Full program initialization calls registerCoreCliByName() which eagerly loads register.status-health-sessions-Db3ewsgh.js with static top-level imports of pi-embedded-iRgRpYxO.js (1.5MB, 40K lines, 214 imports).

  3. pi-embedded transitively imports provider modules with top-level non-lazy calls to loadBundledPluginPublicSurfaceModuleSync() via jiti. Jiti compiles TypeScript plugins synchronously — 35 such calls across 45 modules, each 1.5–5 seconds, no cross-process cache.

Fix Action

Fix / Workaround

#3 dist/run-main-Cv4tme_8.js:tryRouteCli()if (hasHelpOrVersion(argv)) return false disables efficient routed dispatch for all help requests, sending them to the full bootstrap path.

RAW_BUFFERClick to expand / collapse

Summary

openclaw <subcommand> --help blocks for 10–22 seconds on every invocation. The root --help fast path (openclaw --help) works correctly at ~165ms. The regression affects all subcommands that trigger full program initialization: status, agent, secrets, gateway, sessions, tasks, etc.

Measurements

CommandTime
openclaw --help~165ms (fast path works)
openclaw --version~663ms
openclaw status --help~20s
openclaw agent --help~22s
openclaw secrets --help~12s
Node.js bare startup~120ms (baseline)

Environment: Node.js v22.22.1, Ubuntu 22.04, OpenClaw 2026.3.31

Root Cause

Three interacting issues cause the slowdown:

  1. tryRouteCli() in run-main-Cv4tme_8.js (~line 290) bails out with if (hasHelpOrVersion(argv)) return false, forcing all subcommand --help invocations through full program initialization.

  2. Full program initialization calls registerCoreCliByName() which eagerly loads register.status-health-sessions-Db3ewsgh.js with static top-level imports of pi-embedded-iRgRpYxO.js (1.5MB, 40K lines, 214 imports).

  3. pi-embedded transitively imports provider modules with top-level non-lazy calls to loadBundledPluginPublicSurfaceModuleSync() via jiti. Jiti compiles TypeScript plugins synchronously — 35 such calls across 45 modules, each 1.5–5 seconds, no cross-process cache.

Top 3 Bottlenecks

#1 dist/facade-runtime-D_UMLPAC.js — 35 top-level const assignments trigger jiti TypeScript compilation per module load. pi-embedded full load: ~17.7s measured.

#2 dist/register.status-health-sessions-Db3ewsgh.js — static import of pi-embedded at top-level forces the full 1.5MB bundle on every subcommand invocation including --help.

#3 dist/run-main-Cv4tme_8.js:tryRouteCli()if (hasHelpOrVersion(argv)) return false disables efficient routed dispatch for all help requests, sending them to the full bootstrap path.

Bonus: module.enableCompileCache() fails silently (permission denied on cache dir). Setting NODE_COMPILE_CACHE=~/.cache/node recovers 30–50ms per invocation.

Proposed Fixes

  1. Set NODE_COMPILE_CACHE in openclaw.mjs (2 lines, zero risk)
  2. Extend cli-startup-metadata.json with precomputed subcommand help texts
  3. Convert top-level facade const assignments to lazy getters (post-build transform)
  4. Extend tryRouteCli() to handle subcommand --help without loading pi-embedded
  5. Convert static imports in register modules to dynamic import() inside handlers

Analyzed: Node.js v22.22.1 · OpenClaw 2026.3.31 · 2026-04-01

extent analysis

TL;DR

Setting NODE_COMPILE_CACHE and optimizing tryRouteCli() to handle subcommand --help without full program initialization are likely fixes for the slowdown.

Guidance

  • Verify the NODE_COMPILE_CACHE environment variable is set correctly and accessible to recover 30-50ms per invocation.
  • Investigate modifying tryRouteCli() to efficiently handle subcommand --help requests without loading pi-embedded.
  • Consider converting top-level facade const assignments to lazy getters to reduce the overhead of jiti TypeScript compilation.
  • Evaluate extending cli-startup-metadata.json with precomputed subcommand help texts to bypass full program initialization for --help requests.

Example

No specific code snippet is provided due to the complexity of the issue, but modifying tryRouteCli() to handle subcommand --help without full program initialization could look like optimizing the conditional logic to return early for --help cases.

Notes

The proposed fixes involve modifying the code and environment variables, which may require testing and validation to ensure they do not introduce new issues. The NODE_COMPILE_CACHE setting has zero risk, but other changes may have unintended consequences.

Recommendation

Apply the workaround by setting NODE_COMPILE_CACHE and consider optimizing tryRouteCli() to handle subcommand --help requests efficiently, as these changes have a low risk of introducing new issues and can potentially recover significant time per invocation.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING