Skip to content

perf(agents): memoize XML attribute regex in DSML stream parser - #92034

Merged
vincentkoc merged 1 commit into
openclaw:mainfrom
hansraj316:perf/xml-attribute-regex-memo
Jun 10, 2026
Merged

vincentkoc merged 1 commit into
openclaw:mainfrom
hansraj316:perf/xml-attribute-regex-memo

Conversation

@hansraj316

Copy link
Copy Markdown
Contributor

Summary

parseXmlAttribute compiled a fresh RegExp on every call inside the DeepSeek DSML streaming parser's parameter scan. Memoize by attribute name via a module-level Map and escape the name; the cached regex is non-global so behavior is identical.

  • Files: src/agents/openai-transport-stream.ts
  • No CHANGELOG.md edit (release-only per AGENTS.md).

Why core (not ClawHub)

Core performance fix touching src/agents/openai-transport-stream.ts — per AGENTS.md these stay in core (security/core hardening, bundled regressions, missing core APIs), not optional skill bundles routed to ClawHub.

Verification

  • node scripts/run-vitest.mjs run src/agents/openai-transport-stream.test.ts => 241 passed
  • pnpm tsgo:core (tsconfig.core.json) => clean
  • oxfmt --check + oxlint on touched files => clean

Real behavior proof

  • Behavior addressed: The DSML streaming parser no longer recompiles the attribute matcher per call; output is identical.
  • Real environment tested: macOS (Darwin 25.3.0); OpenClaw at base 2accfee; Node 22; Vitest via scripts/run-vitest.mjs.
  • Exact steps or command run after this patch: node scripts/run-vitest.mjs run src/agents/openai-transport-stream.test.ts
  • Evidence after fix: 241 tests pass, incl. a new case asserting repeated DSML parses across separate stream invocations return identical results (no stale regex state).
  • Observed result after fix: Cached regex has no g/y flag (no lastIndex state to leak); attribute name is regex-escaped; cache is process-local and effectively single-entry.
  • What was not tested: Perf delta not micro-benchmarked; full Crabbox; Linux CI.. Independently reviewed by a separate agent before commit; not yet run through Crabbox/$autoreview.

🤖 Generated with Claude Code

parseXmlAttribute compiled a fresh RegExp on every call in the DeepSeek DSML
streaming parser. Memoize by attribute name via a module-level Map and escape
the name; behavior unchanged (non-global regex).
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI. labels Jun 10, 2026
@vincentkoc vincentkoc self-assigned this Jun 10, 2026
@vincentkoc

Copy link
Copy Markdown
Member

Maintainer verification complete.

  • Rebased onto current origin/main.
  • Focused proof: node scripts/run-vitest.mjs src/agents/openai-transport-stream.test.ts — 250 tests passed.
  • Fresh autoreview: clean, no accepted/actionable findings.
  • The memoized regex is non-global, escaped, and currently bounded to the fixed name attribute.

@vincentkoc
vincentkoc merged commit 91cc69d into openclaw:main Jun 10, 2026
178 of 184 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jun 11, 2026
…claw#92034)

parseXmlAttribute compiled a fresh RegExp on every call in the DeepSeek DSML
streaming parser. Memoize by attribute name via a module-level Map and escape
the name; behavior unchanged (non-global regex).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: S triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants