perf(plugins): memoize metadata snapshots per process#81064
Conversation
|
Codex review: needs maintainer review before merge. Summary Reproducibility: yes. at source/proof level: current main has many loadPluginMetadataSnapshot callers and no outer snapshot memo, while the PR body provides before/after terminal timing for real CLI commands on a 104-plugin install. I did not recreate that large install locally in this read-only checkout. Real behavior proof Next step before merge Security Review detailsBest possible solution: Land a fingerprint-keyed, process-scoped metadata snapshot memo only after CI and plugin-area review confirm the cache stays fresh across install, discovery, and lifecycle boundaries. Do we have a high-confidence way to reproduce the issue? Yes, at source/proof level: current main has many loadPluginMetadataSnapshot callers and no outer snapshot memo, while the PR body provides before/after terminal timing for real CLI commands on a 104-plugin install. I did not recreate that large install locally in this read-only checkout. Is this the best way to solve the issue? Likely yes: keying a single-slot process memo on caller params plus discovery fingerprints and cloning returned snapshots is a narrow implementation for the repeated in-process rebuild cost. Because the cache surface is broad and plugin guidance is strict about metadata freshness, maintainer review and CI should remain the merge gate. What I checked:
Likely related people:
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 6a5290e49e2b. |
Summary
loadPluginMetadataSnapshotonce per process, keyed by caller params plus a stat fingerprint of plugin discovery and installed-index inputs.Root cause
CLI startup calls
loadPluginMetadataSnapshotmultiple times in one process. The lowermanifestMetadataCachededupes only the innermost manifest metadata scan, not registry snapshot construction, manifest registry materialization, owner maps, and fingerprints.Real behavior proof
Behavior or issue addressed:
Repeated in-process plugin metadata snapshot construction dominated CLI startup on a 104-plugin install.
Real environment tested:
Local production OpenClaw install: 2026.5.10-beta.5 (1ba6893), Node v26.1.0, Linux/WSL2, 104 plugins.
Exact steps or command run after this patch:
Temporarily swapped local dist variants with backups/restores, then ran
/usr/bin/time -p timeout 180s openclaw plugins listand/usr/bin/time -p timeout 180s openclaw gateway statusfor each variant. Compared output byte counts, line counts, and SHA-256 hashes.Evidence after fix:
Terminal output from real
openclawCLI commands, summarized from the captured/usr/bin/timeoutput and output hashes:openclaw plugins list7e73d3186b1c2e689f25ee3ce3b8a3407a8eda6060ea2b22063a553d257be796openclaw plugins listopenclaw gateway status5d37de574207a02f7fcdb3ff555e019efc2710c9da37162cb4a42e42d597e811openclaw gateway statusObserved result after fix:
openclaw plugins listimproved from 89.45s to 7.38s, andopenclaw gateway statusfrom 74.34s to 6.74s, with byte-identical/line-identical/hash-identical output. A narrower config/model-defaults-only patch was rejected because it leftopenclaw gateway statusslow (68.35s).What was not tested:
Broad full-suite/build matrix locally. The local proof was captured against an equivalent production dist patch; this PR adds stricter invalidation coverage on top of that optimization path.
Verification
pnpm test src/plugins/plugin-metadata-snapshot.memo.test.ts src/plugins/manifest-metadata-scan.test.ts src/plugins/manifest-model-id-normalization.test.tspnpm format:check src/plugins/manifest-metadata-scan.ts src/plugins/plugin-metadata-snapshot.memo.test.tsgit diff --checkpnpm tsgo:core