Skip to content

improve(plugins): reduce mutable argument handling overhead - #152154

Merged
steipete merged 1 commit into
mainfrom
codex/perf-immutable-root-5152
Sep 18, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf-immutable-root-5152

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Plugin calls repeatedly allocate traversal state while checking ordinary mutable message objects for immutability.

User Impact

Plugin argument handling does less allocation work for mutable message payloads. Plugin behavior, mutation handling, and object identity remain unchanged; no configuration or migration is required.

Why This Change Was Made

Reject roots that cannot be deeply frozen plain data before allocating the traversal set and queue. Retain the existing positive cache and full graph validation for eligible roots.

Evidence

  • Four fresh processes in fixed baseline/candidate/candidate/baseline order exercised the actual plugin call boundary, with 8,008 calls per process across five payload shapes.
  • Mutable-message wall time improved 5.5% and 9.4% in the two pairs; process CPU improved 7.2% and 10.8%. These are component measurements, not Gateway-wide latency gains.
  • Other shapes were mixed. The frozen-cycle case regressed 7.2% in the first pair and improved 31.7% in the second; warm frozen configuration varied by a few microseconds per 100 calls. Fresh-frozen gains are not attributed to this change because timing drift and garbage collection remain confounders.
  • All fixture identity, mutation, handle restoration, aliasing, and disposal assertions passed. Source, runtime, dependency, and fixture identities stayed fixed throughout the comparison.
  • 135 existing plugin argument and callback tests passed. Formatting and diff checks passed.
  • Independent review completed with no P0–P2 findings. The local full changed-check lane was not run; exact-head hosted CI must pass before native landing.

@steipete steipete self-assigned this Sep 18, 2026
@clawsweeper

clawsweeper Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added size: XS maintainer Maintainer-authored PR labels Sep 18, 2026
@steipete
steipete marked this pull request as ready for review September 18, 2026 20:45
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 18, 2026
@clawsweeper

clawsweeper Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 18, 2026, 5:01 PM ET / 21:01 UTC (Revision 2).

ClawSweeper review

What this changes

The PR avoids allocating graph-traversal state when plugin arguments cannot be deeply frozen plain data.

Merge readiness

✅ Ready for maintainer review

This remains a useful, bounded optimization absent from current main. No actionable correctness or security defect was found, and the earlier merged optimization does not supersede it.

Likely related people: steipete, with high-confidence routing from prior merged work on the same classifier.

Priority: P3
Reviewed head: bbb53f9a9036461d011c6f877d9863e880848a5d

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, behavior-preserving optimization supported by relevant existing tests and carefully bounded author-reported measurements.
Proof confidence 🌊 off-meta tidepool Not applicable: The repository-state maintainer classification exempts this internal optimization from the external-contributor proof gate; the body nevertheless reports comparative runs through the actual plugin call boundary with preserved behavior assertions.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The repository-state maintainer classification exempts this internal optimization from the external-contributor proof gate; the body nevertheless reports comparative runs through the actual plugin call boundary with preserved behavior assertions.
Evidence reviewed 6 items Introduced change preserves classification: The pinned merge-base-to-head diff adds only the early root check. It uses the same predicate already applied inside traversal, follows the positive cache lookup, and leaves graph-wide cache publication unchanged. Proxies are rejected before reflection.
Current-main necessity and release check: Fetched main still allocates the traversal set and array before rejecting a mutable root. The corresponding shared module is absent from the supplied latest release tag, v2026.9.4; no shipped equivalent was established.
Production boundary and existing coverage: Argument restoration consults the classifier before traversing caller data. The complete existing argument test file covers identity, restored handles, aliases, sparse arrays, descriptors, opaque proxies/accessors, mutable updates, disposal, and frozen cycles reaching mutable descendants. Tests were inspected, not executed.
Findings None None.
Security None None.

How this fits together

OpenClaw classifies argument and configuration objects so plugin calls and configuration readers can safely reuse immutable data. This shared classifier feeds argument restoration and in-memory caching decisions.

flowchart TD
  A[Arguments and configuration] --> B[Immutable data classifier]
  B --> C{Previously validated?}
  C -->|Yes| F[Reuse immutable data]
  C -->|No| D{Plain frozen root?}
  D -->|No| G[Normal mutable data handling]
  D -->|Yes| E[Validate complete graph]
  E -->|Valid| F
  E -->|Invalid| G
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +3. Total +3 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 1 3 0 +3
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 3 0 +3

Review metrics

None.

Technical review

Best possible solution:

Retain the shared classifier and its positive cache while rejecting ineligible roots before allocating traversal state.

Do we have a high-confidence way to reproduce the issue?

Not applicable as a functional bug: source confirms avoidable traversal allocations, and the author reports comparative component measurements; this read-only review did not execute benchmarks.

Is this the best way to solve the issue?

Yes. The early check reuses the existing classification rule without changing callers, cache lifetime, or plugin APIs.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against eed0fcc30c4b.

Labels

Label justifications:

  • P3: This is an internal allocation optimization with no intended user-visible behavior, configuration, or migration change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The repository-state maintainer classification exempts this internal optimization from the external-contributor proof gate; the body nevertheless reports comparative runs through the actual plugin call boundary with preserved behavior assertions.

Evidence

What I checked:

  • Introduced change preserves classification: The pinned merge-base-to-head diff adds only the early root check. It uses the same predicate already applied inside traversal, follows the positive cache lookup, and leaves graph-wide cache publication unchanged. Proxies are rejected before reflection. (src/shared/immutable-data.ts:25, bbb53f9a9036)
  • Current-main necessity and release check: Fetched main still allocates the traversal set and array before rejecting a mutable root. The corresponding shared module is absent from the supplied latest release tag, v2026.9.4; no shipped equivalent was established. (src/shared/immutable-data.ts:25, eed0fcc30c4b)
  • Production boundary and existing coverage: Argument restoration consults the classifier before traversing caller data. The complete existing argument test file covers identity, restored handles, aliases, sparse arrays, descriptors, opaque proxies/accessors, mutable updates, disposal, and frozen cycles reaching mutable descendants. Tests were inspected, not executed. (src/plugins/plugin-instance-arguments.test.ts:215, bbb53f9a9036)
  • Related merged work remains distinct: GitHub confirms refactor(shared): reduce immutable graph traversal allocations #152077 merged as this commit. Its patch replaces recursive traversal with a stack but retains allocation before root rejection, so it does not implement this PR's additional shortcut. Commit metadata and GitHub attribution connect steipete to that prior work. (src/shared/immutable-data.ts:29, 219dd689ad0e)
  • Captured behavior evidence: The supplied PR body, captured under sourceRevision ef1689527cca3f7499e119cf436de2feeee7f39db4fbcc322cafc7ecda57a40c, reports four fresh baseline/candidate processes exercising the actual plugin call boundary, 8,008 calls per process, preserved identity/mutation/restoration/disposal assertions, and 135 passing tests. Mutable-message timing improved in both pairs; other shapes were mixed and no Gateway-wide gain was claimed. These results were reported by the author, not rerun during this review. (bbb53f9a9036)
  • Review continuity and read-only checks: The previous completed review retains no findings or published rank-up moves. Its earlier SHA could not be read locally, so revision equivalence was not claimed. The current introduced diff was independently inspected, git diff --check passed, and final git status remained clean. No maintainer-notes directory or additional ancestor AGENTS.md exists for the changed shared file. (src/shared/immutable-data.ts:25, bbb53f9a9036)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-18T20:49:35.568Z sha 63a5d394bfcc285249687d719cfdb59f0f63333a :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the codex/perf-immutable-root-5152 branch from 63a5d39 to bbb53f9 Compare September 18, 2026 20:55
@steipete
steipete merged commit 8380eb6 into main Sep 18, 2026
206 checks passed
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@steipete
steipete deleted the codex/perf-immutable-root-5152 branch September 18, 2026 21:34
vincentkoc added a commit that referenced this pull request Sep 18, 2026
…n-20260918-v4

* origin/main: (81 commits)
  fix: retire failed setup plugins without replaying facade initialization (#152026)
  fix(test): select Node for built runtime recovery fixtures (#152162)
  refactor(auth): reuse privately assembled choice groups (#152166)
  fix: preserve chat media delivery and session boundaries (#152079)
  fix: keep stale Stop messages from canceling replacement sessions (#152116)
  improve(plugins): reduce mutable argument handling overhead (#152154)
  fix(scripts): prevent host tooling drift from blocking PR workflows (#152078)
  improve: reduce model capability preparation work (#152128)
  fix: stop marking delivered scheduled reports as failed (#152165)
  fix: start background context maintenance after durable turns (#151936)
  fix(models): avoid ambient state reads during prepared selection (#152119)
  feat: recover abandoned Crabbox source staging (#152006)
  chore(ui): refresh control ui locales (#152098)
  fix(ui): keep cloud startup prompts and progress in chat (#152024)
  fix: report completed subprocess cleanup after cancellation (#152107)
  perf(reply): reuse normalized inbound text (#152110)
  fix(cron): paused future one-shots disappear after Run now (#152126)
  perf(sessions): reuse rows and skip discarded terminal labels (#152109)
  fix(ui): keep keyboard-focused automation controls clear of sticky actions (#152135)
  fix(ui): load remote images in compact activity previews (#152045)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant