Skip to content

perf(gateway): avoid temporary profile reference projections - #179796

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-session-list-profile-reference-20260919
Oct 21, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-session-list-profile-reference-20260919

Conversation

@steipete

@steipete steipete commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Person-filtered sessions.list requests repeatedly flatten every visible session's creator and participants into temporary arrays. ID-only callers also build participant display objects that they immediately discard.

User Impact

The same sessions, people, owners, and profile links are returned with less allocation. Exact references, retained identities, merged profiles, prefix ambiguity, and viewer-specific disclosure retain their existing semantics. No configuration, schema, cache, or invalidation change.

Why This Change Was Made

Scan raw creator/participant identities with two request-scoped callbacks, preserving creator-first exact-match precedence. Reuse the existing profile identity map through one ID resolver; display projection and ID-only callers consume that same owner. With 5,000 rows and three participants, a full scan no longer constructs 25,000 temporary arrays and 5,000 flatMap callbacks (source-derived counts).

Production delta: 33 insertions, 33 deletions (net zero) across the two Gateway modules. The added code outside those modules is reproducible benchmark/capture tooling. This is a simplification; whole-Gateway allocation noise is too large to establish a small owner's improvement.

Evidence

Owner replay: Node 26.8.2 on an isolated Linux sandbox, 5,000 sessions, 50 profile identities including aliases and retained identities, three participants per session, 27 requests across three visibility scopes. Five serial interleaved A/B samples per side, each after 54 warmups and containing 108 measured filter operations. Both include-collected allocation sampling flags enabled. All 27 golden filter results are byte-identical across all pairs.

Owner metric Before median After median Change Before / after p95 (context only, n=5 samples per side)
Sampled allocated bytes / filter operation 7,161,220 5,969,453 −16.6% 7,281,216 / 5,981,551
Thread CPU ms / filter operation 2.953 2.282 −22.7% 3.451 / 2.569
node --expose-gc --import ./scripts/tsx.mjs scripts/perf/session-profile-reference-measure.ts \
  --iterations 108 --output sample.json --golden responses.json

Focused local validation: 38 tests passed across session-utils-profile-reference, session-utils-owners, and session-utils.filters; 22 import/wrapper closure tests passed; export-name collision guard, changed-file format/lint, and pnpm tsgo:core passed. Independent Codex autoreview is clean at P0–P2. PR CI supplies broad validation.

Gateway no-regression result

Pass under decision rule v5; land as a net-zero production simplification. Two concurrent A/B pairs used interleaved 16-core placements, with baseline/candidate swapped in pair 2. Pair 1 used slot A (baseline even 96–126, candidate odd 97–127); pair 2 used slot B (baseline odd 65–95, candidate even 64–94). The mean of within-pair percentage changes cancels residual placement bias. No gated metric has mean regression ≥20% or regression ≥10% in both pairs.

Each side used 120 s warmup and 480 s measurement, 5,000 retained sessions, 6,000 retained runs, 16 clients, 12 concurrent turns, 50 streamed chunks, and missing-prefix person-filter polling every 500 ms. Fixtures used 1 MiB transcript payload and one project. Both sides completed 32 measured cohorts / 384 turns, plus eight warmup cohorts; resets were 0/0 in both pairs. Both diagnostic captures had no dropped events, histogram samples, or collection errors.

Metric Pair 1 A Pair 1 B Δ1 Pair 2 A Pair 2 B Δ2 Mean Δ
Promotion MB/turn 38.053 37.652 -1.05% 39.156 40.926 +4.52% +1.73%
Total GC s/min 1.574 1.521 -3.38% 1.734 1.749 +0.85% -1.26%
Event-loop p99 ms 55.902 (n=20,769) 54.166 (n=20,871) -3.11% 58.229 (n=20,290) 58.360 (n=20,768) +0.23% -1.44%
Turn p95 ms 6689.186 (n=384) 6315.136 (n=384) -5.59% 9051.261 (n=384) 7562.150 (n=384) -16.45% -11.02%
sessions.list p99 ms 81.788 (n=8,083) 83.138 (n=8,048) +1.65% 126.450 (n=8,624) 98.148 (n=8,265) -22.38% -10.37%
Sampled allocation MB/turn (context) 247.491 231.334 -6.53% 250.279 236.251 -5.60% -6.07%
Minor GC s/min (context) 1.285 1.265 -1.54% 1.426 1.464 +2.73% +0.59%
Major GC s/min (collections) 0.290 (n=66) 0.256 (n=60) -11.50% 0.309 (n=63) 0.285 (n=58) -7.81% -9.66%
Turn p99 ms (context only) 8654.550 (n=384) 9204.902 (n=384) +6.36% 11665.181 (n=384) 9111.625 (n=384) -21.89% -7.77%

p99 gates require ≥1,000 samples per side; turn p95 gates have ≥200 per side. Turn p99 is context only at n=384 per side. Major-GC collection counts are shown explicitly; total GC carries the gate. Whole-Gateway sampled allocation is context only: this experiment is not powered to attribute a small owner's allocation win. Promotion's +1.73% mean is within the predeclared no-regression limit.

All 24 captured full RPC responses matched in both pairs after normalizing only response/snapshot timestamps and each isolated fixture's absolute root. The resulting normalized response hashes also match across pairs. The owner replay separately proves 27 byte-identical results across viewer scopes without normalization.

node --import ./scripts/tsx.mjs scripts/perf/transcript-broadcast-measure.ts \
  --entry src/entry.ts --state-dir <fixture> --scenario memory-soak \
  --allocations --trace-gc --diagnostics --capture-responses \
  --clients 16 --runs 12 --chunks 50 --chunk-interval-ms 10 \
  --warmup-ms 120000 --duration-ms 480000 --round-interval-ms 15000 \
  --retained-profile-ms 0 --reset-every-rounds 0 --list-interval-ms 500 \
  --list-profile-reference ffffffff --poll-seed lane1553 \
  --port <isolated-loopback-port> --mock-port <isolated-provider-port> \
  --start-at <shared-epoch-ms>

Every side ran in a resource-limited systemd scope with CPUWeight/IOWeight 10, 32 GiB MemoryMax, and the shared production guard. One transient guard sample in pair 2 recovered on the next check; neither valid pair was aborted. An earlier setup attempt missed the shared startup deadline on both sides and produced no measurement; it was discarded, fixtures regenerated, and the startup allowance raised from 210 to 300 seconds. Source, workload, and measurement duration were unchanged. Synthetic provider/state and disabled plugins limit this evidence to the exercised session-list path, not plugin-invocation performance.

CI and review

Independent Codex autoreview is clean at P0–P2; hosted Codex review completed with no findings. Exact-head CI run 39654618593 passed all selected jobs except one inherited UI test file and its aggregate gate.

Inherited failure: ui/src/e2e/boot-module-boundaries.e2e.test.ts, the sidebar-download recovery cases at 390px and 1280px, both time out on Retry now at gateway-module-boundaries.test-support.ts:62. PR job 119412335759 and scheduled main job 119376935880 show the same assertions and 30-second locator.isDisabled timeouts. The test uses a mock Gateway; the entire UI tree is unchanged by this PR. CI's automatic classification says unknown solely because PR UI shards are 1/2 while scheduled main uses 1/9. No CI rerun was requested.

The inspected CI checkout is 582b1a14af96937f800446c1066aea81b531c9c8, with ordered parents 200d82b012aaf4e937da13c0788828ce1a8c560f and this PR's exact head e2262b8f0d519b629e18902655c8b778ae83d474. Security, type, lint, closure, and affected Node test jobs passed. The sandbox baseline was e18310f1ba35; the intervening main commits incorporated before push changed none of the measured owner/harness paths.

Related: #179211.

Preserve raw retained identities and viewer-specific person filtering while scanning existing participants directly. Share profile ID resolution with display projection and remove display object allocation from ID-only callers. Add reproducible owner allocation measurements and person-filtered Gateway soak captures.
@clawsweeper

clawsweeper Bot commented Oct 21, 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 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-21T18:40:30.159327Z e2262b8 PR opened
ℹ️ 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.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime scripts Repository scripts size: M labels Oct 21, 2026
@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 21, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete
steipete merged commit b3245a2 into main Oct 21, 2026
131 of 135 checks passed
@steipete
steipete deleted the steipete/perf-micro-session-list-profile-reference-20260919 branch October 21, 2026 19:46
@steipete

Copy link
Copy Markdown
Contributor Author

Landed as b3245a2 under the authorized inherited-failure exception.

The only failing test file on exact head e2262b8 was ui/src/e2e/boot-module-boundaries.e2e.test.ts: the 390px and 1280px sidebar-download recovery cases time out on Retry now at gateway-module-boundaries.test-support.ts:62. PR job and scheduled main job show the same two failures. The whole UI tree is unchanged in the tested PR merge. All other selected CI jobs, including security, passed; no CI rerun was requested.

Both interleaved, swapped Gateway pairs passed v5, with matched 384 turns and zero resets per side. All 27 owner golden results and 24 normalized full RPC responses matched. The PR body contains the per-side counts, paired deltas, workload, and limitations. The native merge helper refused before submission because it requires a separate review worktree; the lane's one-worktree constraint was preserved using the explicitly authorized exact-SHA REST fallback.

steipete added a commit that referenced this pull request Oct 22, 2026
Revert the ordering facts and sharing-wrapper changes from 2e36582 while preserving #179796 profile-reference handling and #180067 archive filtering. Retain the pin/sidebar-root behavior regression and reusable measurement support.

The owner comparator gain did not produce the required per-request production gain. Gateway pairs were flat (+10% promotion, +1.6% CPU/RPC), and the change added 24 runtime lines. Production profiles include other commits, so the next production profile must establish the effect of this revert.
steipete added a commit that referenced this pull request Oct 22, 2026
Revert 6cb819f (#180067) on top of the #179211 revert, preserving #179796 and later unrelated fixes. Restore archive-prefiltered ordering views and their callers.

Production r182 made filterSessionEntries the top OpenClaw self frame: 233 to 1751 samples, inclusive selectSessionEntries samples/rpm 8.27 to 25.2, and main-thread busy 37% to 57% despite lower traffic. All 108 golden cases remain identical to the historical owner path.
steipete added a commit that referenced this pull request Oct 22, 2026
…179211 and #180067 (#180166)

* revert(gateway): restore sessions.list ordering before #179211

Revert the ordering facts and sharing-wrapper changes from 2e36582 while preserving #179796 profile-reference handling and #180067 archive filtering. Retain the pin/sidebar-root behavior regression and reusable measurement support.

The owner comparator gain did not produce the required per-request production gain. Gateway pairs were flat (+10% promotion, +1.6% CPU/RPC), and the change added 24 runtime lines. Production profiles include other commits, so the next production profile must establish the effect of this revert.

* revert(gateway): restore archive-specific session list filtering

Revert 6cb819f (#180067) on top of the #179211 revert, preserving #179796 and later unrelated fixes. Restore archive-prefiltered ordering views and their callers.

Production r182 made filterSessionEntries the top OpenClaw self frame: 233 to 1751 samples, inclusive selectSessionEntries samples/rpm 8.27 to 25.2, and main-thread busy 37% to 57% despite lower traffic. All 108 golden cases remain identical to the historical owner path.

* chore(perf): remove retired session ordering benchmark registration
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 22, 2026
…w#179796)

Preserve raw retained identities and viewer-specific person filtering while scanning existing participants directly. Share profile ID resolution with display projection and remove display object allocation from ID-only callers. Add reproducible owner allocation measurements and person-filtered Gateway soak captures.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 22, 2026
…penclaw#179211 and openclaw#180067 (openclaw#180166)

* revert(gateway): restore sessions.list ordering before openclaw#179211

Revert the ordering facts and sharing-wrapper changes from e3c341e while preserving openclaw#179796 profile-reference handling and openclaw#180067 archive filtering. Retain the pin/sidebar-root behavior regression and reusable measurement support.

The owner comparator gain did not produce the required per-request production gain. Gateway pairs were flat (+10% promotion, +1.6% CPU/RPC), and the change added 24 runtime lines. Production profiles include other commits, so the next production profile must establish the effect of this revert.

* revert(gateway): restore archive-specific session list filtering

Revert f46e5d9 (openclaw#180067) on top of the openclaw#179211 revert, preserving openclaw#179796 and later unrelated fixes. Restore archive-prefiltered ordering views and their callers.

Production r182 made filterSessionEntries the top OpenClaw self frame: 233 to 1751 samples, inclusive selectSessionEntries samples/rpm 8.27 to 25.2, and main-thread busy 37% to 57% despite lower traffic. All 108 golden cases remain identical to the historical owner path.

* chore(perf): remove retired session ordering benchmark registration
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