Skip to content

perf(gateway): prepare session event field order once per audience - #183877

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-session-event-broadcast-20260919
Oct 25, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-session-event-broadcast-20260919

Conversation

@steipete

@steipete steipete commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Session-event fanout repeatedly enumerates and sorts the same presented row when recipients have different delivered histories and negotiate field references.

User Impact

Reduces allocation and CPU work during session updates while preserving each recipient's payload, delivery history, and live permission checks.

Why This Change Was Made

Retain the filtered, sorted field list on the existing publication-local audience. Field-reference comparisons still use each delivery's own payload. Projection/access revision invalidation already replaces the audience, so the prepared order has the same lifetime as its row. Runtime code grows by one net line to carry this prepared value; there is no second preparation path.

Evidence

  • Regression on base 2992c0b8dd4f7165c0420601cbb7b51720225b54: two audience rows were each enumerated twice, failing the expected once-per-audience count. Existing decoded-payload, mixed-capability, history, and permission-revocation assertions remain.
  • Owner benchmark: 66 recipients, three authorization audiences; divergent and aligned delivery histories; five counterbalanced pairs of 500 publications per arm. CPU measured without allocation tracing; allocation sampled in separate passes. Exact recipient frame bytes match.
History Metric / publication Base Candidate Mean absolute delta
Divergent Field enumerations 66 3 −63
Divergent Main-thread CPU 1.858 ms 1.323 ms −0.535 ms (−28.8%)
Divergent Sampled allocation 5.016 MB 3.991 MB −1.026 MB (−20.4%)
Aligned control Field enumerations 3 3 0
Aligned control Main-thread CPU 0.533 ms 0.528 ms −0.005 ms (−0.9%, mixed signs)
Aligned control Sampled allocation 1.021 MB 1.038 MB +0.016 MB (+1.6%)

All five divergent-history pairs improved CPU and allocation. Mean paired percentage changes were −28.79% CPU and −20.23% allocation; table percentages compare the means. The aligned control is effectively neutral, with mixed CPU signs and a small allocation increase. Per-arm host-load observations were 1.37–1.98 for divergent histories and 1.70–1.77 for aligned histories. No samples were discarded.

Reproduce from the committed script's header: save the PR-base projection source (72379bfe686ab07ff8e69162013779f72ee0d4ea) for a fresh comparison, then run node --import ./scripts/tsx.mjs scripts/perf/session-event-field-order.ts --baseline-source <saved-source> --publications 500 --pairs 5. Measurements ran in an isolated Linux sandbox under the shared measurement lock.

Pre-rebase validation: 9/9 focused tests passed across session-row-delta-audiences, session-row-publication-authority, and session-row-delta-delivery; changed-file type-aware lint, formatting, diff whitespace, and export-name collision checks passed. The changed audience test file took 6.71 seconds of test execution; the first uncached baseline invocation took 725.67 seconds including module-cache preparation. Exact-head CI completed successfully; see the final validation result below.

Independent subagent review (autoreview route unavailable) found no actionable P0–P2 findings. The canonical helper refused the configured provider route because it did not match the operator configuration; no configuration was changed. An earlier lint invocation selected the wrong configuration and timed out preparing plugin declarations before lint; the corrected source-backed lint configurations passed.

The required eager-import and PR-wrapper closure checks passed (22/22 tests; 112.38 seconds total). Runtime source delta: +1 line; regression delta: +11 lines; benchmark/tooling delta: +356 lines (+357 non-test lines total). The committed benchmark and exact executable-root registration provide reproducible measurement tooling.

The benchmark measures the real projection/broadcast owners with synthetic state and in-memory sockets. It does not establish whole-Gateway latency or throughput; the scoped duplicate-work deletion uses owner measurements and focused boundary proof rather than a ten-minute Gateway stress campaign.

Rebased cleanly onto 72379bfe686ab07ff8e69162013779f72ee0d4ea before the final push. The upstream projection change adds one nullable envelope field; the optimization patch is unchanged and incremental independent review is clean. The numerical comparison above remains evidence from the explicitly pinned base, and exact-head PR CI passed on the integrated head.

The first CI run found an implicit-any parameter in the benchmark instrumentation. It is now typed from the built-in Object.entries contract; targeted pnpm tsgo:scripts and benchmark lint pass, and independent review of the repair is clean. The repair has no runtime effect.

Final validation: CI run 40237891003 completed successfully on b33b2c87b0406c915407389056b8f5be1a6a4e01, including the browser-extension end-to-end job. GitHub code review also completed on that exact head with no findings. The initial failing CI run was superseded by the benchmark type repair; no jobs were rerun to chase green.

@clawsweeper

clawsweeper Bot commented Oct 25, 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 gateway Gateway runtime scripts Repository scripts size: M labels Oct 25, 2026
@steipete
steipete marked this pull request as ready for review October 25, 2026 21:47
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 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-25T21:59:22.691833Z b33b2c8 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-session-event-broadcast-20260919 branch from 31a87e4 to b33b2c8 Compare October 25, 2026 21:57
@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 25, 2026
@steipete
steipete merged commit 739b708 into main Oct 25, 2026
138 of 139 checks passed
@steipete
steipete deleted the steipete/perf-micro-session-event-broadcast-20260919 branch October 25, 2026 22:11
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 26, 2026
…penclaw#183877)

* perf(gateway): prepare session event field order once per audience

* fix(perf): type session field-order benchmark instrumentation
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. gateway Gateway runtime scripts Repository scripts size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant