Thanks to visit codestin.com
Credit goes to github.com

Skip to content

perf(plugins): memoize metadata snapshots per process#81064

Open
Kaspre wants to merge 1 commit into
openclaw:mainfrom
Kaspre:perf/plugin-metadata-snapshot-process-memo
Open

perf(plugins): memoize metadata snapshots per process#81064
Kaspre wants to merge 1 commit into
openclaw:mainfrom
Kaspre:perf/plugin-metadata-snapshot-process-memo

Conversation

@Kaspre
Copy link
Copy Markdown
Contributor

@Kaspre Kaspre commented May 12, 2026

Summary

  • Memoize loadPluginMetadataSnapshot once per process, keyed by caller params plus a stat fingerprint of plugin discovery and installed-index inputs.
  • Clear the memo at current-metadata lifecycle set/clear boundaries.
  • Expand the metadata fingerprint to cover persisted installs, install-record recovery, configured load paths, recovered npm installs, bundled/global/workspace/source-checkout roots, package/bundle/default metadata files, package-declared runtime/setup outputs, provider catalog runtime outputs, nested candidates, symlinked roots, persisted diagnostic source paths, provided installed indexes, plugin root safety metadata, and ctime-aware file stats.
  • Clone cached metadata/snapshot returns so callers cannot mutate cached state.
  • Add regression coverage for stale invalidation and cache-aliasing cases.

Root cause

CLI startup calls loadPluginMetadataSnapshot multiple times in one process. The lower manifestMetadataCache dedupes 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 list and /usr/bin/time -p timeout 180s openclaw gateway status for each variant. Compared output byte counts, line counts, and SHA-256 hashes.

Evidence after fix:
Terminal output from real openclaw CLI commands, summarized from the captured /usr/bin/time output and output hashes:

Variant Command real user sys Output
snapshot memo patch (this PR approach) openclaw plugins list 7.38s 7.11s 2.12s 45918 bytes / 341 lines / 7e73d3186b1c2e689f25ee3ce3b8a3407a8eda6060ea2b22063a553d257be796
unpatched beta.5 openclaw plugins list 89.45s 59.92s 32.47s same bytes/lines/hash
snapshot memo patch openclaw gateway status 6.74s 5.62s 2.03s 950 bytes / 24 lines / 5d37de574207a02f7fcdb3ff555e019efc2710c9da37162cb4a42e42d597e811
unpatched beta.5 openclaw gateway status 74.34s 49.54s 26.95s same bytes/lines/hash

Observed result after fix:
openclaw plugins list improved from 89.45s to 7.38s, and openclaw gateway status from 74.34s to 6.74s, with byte-identical/line-identical/hash-identical output. A narrower config/model-defaults-only patch was rejected because it left openclaw gateway status slow (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.ts
  • pnpm format:check src/plugins/manifest-metadata-scan.ts src/plugins/plugin-metadata-snapshot.memo.test.ts
  • git diff --check
  • pnpm tsgo:core
  • Multi-lane review gate: no blockers
  • Claude review gate: no blockers
  • Codex review gate: no prioritized, actionable correctness issues

@openclaw-barnacle openclaw-barnacle Bot added size: XL triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 12, 2026
@clawsweeper
Copy link
Copy Markdown
Contributor

clawsweeper Bot commented May 12, 2026

Codex review: needs maintainer review before merge.

Summary
The PR adds a process-local memo for plugin metadata snapshots, expands the manifest discovery fingerprint used as the cache key, clears the memo on metadata lifecycle changes, and adds memo invalidation/aliasing tests.

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
Sufficient (terminal): Sufficient terminal proof is supplied in the PR body: it shows after-fix real CLI timings, before/after comparisons, and identical output hashes for the changed behavior.

Next step before merge
No automated repair is needed; this open PR has no discrete actionable defect from this review and should proceed through normal maintainer and CI validation.

Security
Cleared: Cleared: the diff stays within plugin metadata scanning, memoization, and tests, with no concrete security or supply-chain regression found.

Review details

Best 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:

  • Current main behavior: Current main calls loadPluginMetadataSnapshotImpl directly inside the diagnostics span, so repeated callers rebuild the registry snapshot wrapper work rather than using a process-local snapshot memo. (src/plugins/plugin-metadata-snapshot.ts:176, 6a5290e49e2b)
  • PR memo implementation: At PR head, loadPluginMetadataSnapshot computes a memo key, returns a cloned cached snapshot on hit, stores a cloned snapshot on miss, and reports memo diagnostics attributes. (src/plugins/plugin-metadata-snapshot.ts:184, d0bb9dbefb94)
  • Fingerprint implementation: The PR head builds the memo fingerprint from configured load paths, persisted registry inputs, recovered npm installs, bundled/global/workspace roots, installed indexes, candidate file stats, nested candidates, and diagnostic source paths. (src/plugins/manifest-metadata-scan.ts:886, d0bb9dbefb94)
  • Regression coverage: The new memo test file covers cache hits with fresh literal params, independent returned objects, lifecycle invalidation, env/cwd/index changes, external manifest changes, configured load paths, runtime outputs, and nested candidate metadata changes. (src/plugins/plugin-metadata-snapshot.memo.test.ts:156, d0bb9dbefb94)
  • Plugin boundary context: The scoped plugin guidance says metadata caches must preserve freshness and discourages persistent metadata caches, so this process-local memo is an intentional architecture exception that should receive maintainer review. (src/plugins/AGENTS.md:30, 6a5290e49e2b)
  • Real behavior proof context: The PR body supplies after-fix terminal timing data for real openclaw plugins list and openclaw gateway status runs on a 104-plugin install, with matching output byte counts, line counts, and SHA-256 hashes between patched and unpatched variants. (d0bb9dbefb94)

Likely related people:

  • shakkernerd: Local blame maps the current loadPluginMetadataSnapshot, manifest metadata scan, and current metadata state implementations on main to Shakker, and GitHub commit metadata also shows adjacent diagnostics timeline work in this area. (role: recent area contributor; confidence: high; commits: a5557d1fb54e, c795a1a8ef19; files: src/plugins/plugin-metadata-snapshot.ts, src/plugins/manifest-metadata-scan.ts, src/plugins/current-plugin-metadata-state.ts)
  • steipete: Recent GitHub commit metadata shows plugin metadata snapshot fixes around sparse metadata handling, including a direct touch to src/plugins/plugin-metadata-snapshot.ts. (role: recent adjacent contributor; confidence: medium; commits: 2294f5c95a6f, c58319ff50f6; files: src/plugins/plugin-metadata-snapshot.ts)
  • vincentkoc: GitHub commit metadata shows a recent plugin metadata snapshot cycle fix that introduced the shared current metadata state path touched by this PR. (role: adjacent owner; confidence: medium; commits: a2ec5a7d72f4; files: src/plugins/current-plugin-metadata-state.ts, src/plugins/current-plugin-metadata-snapshot.ts)

Remaining risk / open question:

  • The invalidation fingerprint mirrors a broad discovery/control-plane surface, and I did not run the full test or build lanes in this read-only review.
  • The scoped plugin guidance discourages persistent metadata caches, so maintainers should explicitly accept this process-local memo as the right exception.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 6a5290e49e2b.

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 12, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant