init: OpenClaw Perf Cache — fs.{stat,lstat,realpath}{,Sync} TTL memo for plugin-tree paths

Wraps the global fs functions with a 1s TTL memo, scoped via path
whitelist to plugin-discovery paths only. Workaround for upstream
openclaw issue #86791: `loadPluginMetadataSnapshot()`'s cache-validity
check re-runs `hashWatchedFiles` on every lookup, which walks every
plugin's package.json + manifest + source via realpathSync ->
ancestor lstat chain. On prod t2 with ~100 plugins, one cache-check
pass is ~6 400 lstat + ~400 stat (~6-7s CPU per call). Fires on every
agent turn, every loadConfig() call, every channel routing decision.

This plugin doesn't fix the upstream design; it just absorbs the
repeated stats within a 1s window so the same paths aren't re-statted
6× per second during a discovery walk.

Verified on prod t2 (2026-05-27):
  - Cache hit ratio: 92.1-98.2% (stable across windows)
  - Idle baseline (0 turn, 0 push): 0.6-3.7% CPU (was 25%+ pre-fix)
  - Per-turn cost: notably reduced; previously 100% sustained per turn

Path whitelist:
  - /openclaw/dist/extensions/
  - /.openclaw/plugins/
  - /node_modules/@openclaw/
  - /openclaw/plugin-sdk/

All other paths pass through to original fs functions unchanged.

Manifest requires `activation.onStartup: true` so openclaw register()s
the plugin even though it exposes no tools/contracts (otherwise jiti
caches the module without ever calling register).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
h z
2026-05-27 10:17:54 +01:00
commit 49bcde41ec
7 changed files with 543 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
{
"id": "openclaw-perf-cache",
"name": "OpenClaw Perf Cache",
"version": "0.1.0",
"description": "Wraps fs.{statSync,lstatSync,realpathSync,promises.{stat,lstat,realpath}} with a short TTL memo for plugin-tree paths only. Workaround for upstream hashWatchedFiles being called on every plugin-metadata-snapshot cache-validity check (~800 statx/call × ~9 turns/hour on prod = sustained ~15-25% CPU baseline).",
"main": "index.js",
"activation": {
"onStartup": true
},
"configSchema": {
"type": "object",
"additionalProperties": false,
"properties": {}
}
}