Skip to content

perf(memory): narrow workspace file worker imports - #181891

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-worker-heap-retention-20260919
Oct 23, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-worker-heap-retention-20260919

Conversation

@steipete

@steipete steipete commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Workspace memory file workers eagerly load the memory database, indexing, and embedding SDK surfaces while serving filesystem watches. Those module graphs remain reachable for the isolate lifetime, even after its watches close.

User Impact

The worker uses the same filesystem and watcher implementations through narrower imports. Watch selection, file content, notifications, error handling, and shutdown behavior are unchanged. In the compiled-worker workload below, post-GC retained heap falls by 61.66 MB per isolate (77.3%).

Why This Change Was Made

Route filesystem operations and path selection through the existing private-local filesystem facade, and logger creation through the diagnostics facade. No new functions, state, cache, configuration, dependency, or SDK subpath. Production LOC: +18/-7 (net +11), entirely import/export declarations; explicit exports preserve the existing SDK ownership boundary while avoiding unrelated runtime owners.

Evidence

Two swapped pairs reduce retained worker heap by 77.3%, GC time by 21.5%, and promotion by 10.7%, with no regression gate triggered. Focused tests and current-head type/lint/changed-test CI pass. Full measurement details and remaining validation limits follow.

Paired measurements and retained-heap analysis

Two concurrent, CPU-swapped pairs on Linux/Node 26.12.1 under one exclusive measurement slot and the shared production-load guard. Each side used 16 interleaved logical CPUs on separate physical cores, with memory/CPU/IO limits. No guard interruption. Both artifacts came from base 4d13198000c5f47561581e28b1d25e676b8334a4, with only this production patch applied to the candidate. Later rebases retained that patch; CI tests current head.

The actual compiled workspace-memory.worker.js served 12 synthetic workspace roots with 24 memory files each. Each side completed 1,000 waves / 12,000 file-change notifications, with exactly 12,000 change events. Forced collections and snapshots ran outside the timed interval. Change latency measures write-start to first notification, not indexing completion; observations within each wave are correlated. This is a worker-specific filesystem workload, not a full Gateway/session-database replay.

Values are baseline → candidate. Paired mean is the arithmetic mean of the two relative deltas; MB means decimal MB.

Metric Pair 1 Pair 2, CPUs swapped Mean paired delta
Worker heap after steady state + GC 79.761 → 18.098 MB 79.762 → 18.101 MB −77.31%; −61.66 MB
Worker heap after closing all watches + GC 78.638 → 16.930 MB 78.638 → 16.933 MB −78.47%; −61.71 MB
Worker GC profiler time / 12,000 changes 1,368.99 → 1,038.03 ms 1,717.79 → 1,396.05 ms −21.45%
Worker promoted bytes / 12,000 changes 522.23 → 469.80 MB 519.29 → 460.11 MB −10.72%
All-isolate trace GC pause time / 12,000 changes 1,641.36 → 1,322.90 ms 2,071.39 → 1,807.24 ms −16.08%
All-isolate promoted bytes / 12,000 changes 550.17 → 497.66 MB 547.20 → 488.05 MB −10.18%
Worker event-loop p99 1.480 → 1.465 ms (196,461 / 197,672 samples) 2.076 → 2.053 ms (199,663 / 202,140) −1.03%; −0.018 ms
Change notification p99 200.53 → 197.28 ms (12,000 / 12,000) 306.29 → 302.27 ms (12,000 / 12,000) −1.47%; −3.63 ms
Whole-process CPU 55.61 → 52.27 s 61.02 → 59.14 s −4.54%
Workspace-worker thread CPU 31.11 → 32.34 s 34.49 → 36.33 s +4.64%, below gates

GC tail context, with collection counts beside each row:

Tail Pair 1 baseline → candidate Pair 2 baseline → candidate
Minor p95 / p99 0.893 / 1.054 → 0.742 / 0.799 ms (1,770 / 1,783 collections) 1.140 / 1.827 → 0.893 / 1.142 ms (1,768 / 1,783)
Major p95 / p99, insufficient samples for tail gates 3.102 / 3.439 → 1.305 / 1.490 ms (67 / 68 collections) 6.500 / 28.761 → 1.716 / 5.584 ms (67 / 66)
Maximum single worker GC pause, any type 3.439 → 2.708 ms 69.112 → 109.787 ms

Decision under v5.3/v5.2: no regression gate triggered. Minor pause-tail mean deltas are below 1 ms and are context. Major tails lack 200/1,000 samples. Pair 2's maximum pause rises but remains below max(50 ms, 2 × 69.112 ms) = 138.225 ms; it is reported rather than discarded. Parent event-loop p99 is inconclusive under the opposing-sign rule: +0.008 ms (+0.62%) and −0.004 ms (−0.20%), both below regression thresholds. GC time and promotion improve in both pairs, and worker event-loop p99 is effectively neutral.

Separate post-GC sandbox snapshots identify the retained owner: loaded file-script nodes fall from 2,453 to 481; strings from 33.86 to 8.38 MB, code from 17.27 to 6.71 MB. Baseline strong root paths include ModuleLoader → LoadCache → ModuleJob → ModuleWrap and global registrations retaining unrelated runtime code. Storage/embedding facade, Kysely, and bundled channel-configuration scripts appear in the baseline and are absent from the candidate. Snapshot node self-size totals include native/snapshot accounting and are not substituted for the worker heap measurements above.

Proof and Limits

  • Focused tests: 3 files, 9 tests passed (file-watcher.filter, memory-files-worker, memory-watch.worker), 62.14 seconds including compilation/import setup.
  • Changed-file oxfmt and type-aware lint passed; export-name collision guard and 22 eager-import/PR-wrapper closure tests passed.
  • Initial PR CI caught five warning assertions still mocking the former logger facade. The mock now follows the focused import; the exact lifecycle file passes all 35 tests (34.25 seconds including compilation/import setup). Current-head changed-extension CI passes.
  • Independent subagent review (autoreview route unavailable): production patch, test correction, and scoped measurement harness have no actionable findings.
  • Both measured runtime artifacts compiled with the same memory-core-only plugin selection. The baseline full packaging command subsequently stopped at CLI startup metadata because that selection omits the browser command; this was not a compilation failure. Candidate sourcePerformance build passed. A complete distributable build is not claimed by this benchmark.
  • PR CI supplies broad type/lint/test checks on e43b26be2feaff2992702aebca7aa572fe64ce53: exact-head run. No Testbox/Crabbox lease was allocated.
  • No production snapshot, restart, or deployment. This improves the workspace-memory isolate; it does not claim to remove the aggregate heap retained by other worker classes.

@clawsweeper

clawsweeper Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: memory-core Extension: memory-core size: XS labels Oct 23, 2026
@steipete
steipete marked this pull request as ready for review October 23, 2026 20:08
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T20:21:02.373265Z e43b26b New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@steipete
steipete force-pushed the steipete/perf-micro-worker-heap-retention-20260919 branch from bd2e973 to e43b26b Compare October 23, 2026 20:19
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 23, 2026
@steipete
steipete merged commit 3e54ff6 into main Oct 23, 2026
149 of 150 checks passed
@steipete
steipete deleted the steipete/perf-micro-worker-heap-retention-20260919 branch October 23, 2026 20:44
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 24, 2026
* perf(memory): narrow workspace file worker imports

* test(memory): follow focused watcher logger import
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. docs Improvements or additions to documentation extensions: memory-core Extension: memory-core size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant