Repository navigation
perf(gateway): avoid repeated session pin checks while sorting - #183967
Merged
steipete merged 1 commit intoOct 26, 2026
Merged
Conversation
Contributor
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
steipete
marked this pull request as ready for review
October 25, 2026 23:50
Contributor
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
steipete
deleted the
steipete/perf-micro-sort-limit-session-entries-20260919
branch
October 26, 2026 00:05
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Oct 26, 2026
This was referenced Oct 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Problem This Solves
Session-list sorting repeatedly parses the same pinned session keys during comparisons, allocating temporary strings and key objects.
User Impact
Ordering, pin eligibility, paging, and returned entry identities stay identical. This reduces sorting work when pins are present; it does not claim a measured whole-Gateway latency improvement.
Why This Change Was Made
Prepare eligibility once for a synchronous sort, on its first comparison involving a pin timestamp. Keep the result in a sort-local set and discard it on return. Unpinned lists and other sort modes never prepare eligibility; subsequent sorts read current entry metadata. The existing comparator remains the ordering owner, including direct callers outside list sorting.
The earlier prepared-key change #179211 was reverted by #180166 after flat Gateway measurements (+1.6% CPU/RPC and +10% promotion) and added retained state/ordering machinery. This change does not restore its row snapshots, caller changes, sharing wrappers, or cross-request cache. Runtime production delta: +22 lines (benchmark +107, tests +65; total non-test delta +129): a lazy preparation callback and its local set preserve the direct-comparator contract without mutating entries or retaining facts between sorts.
Evidence
scripts/perf/session-list-order-measure.mjs, with usage in its header. Synthetic 10,000-session inventory, 80% subagent keys, 200 pinned dashboard entries or zero pins; 2,500 sorts per case; separate untraced CPU/GC and allocation-sampling passes. Baselinee79654199eb1; the measured import closure is unchanged by the pre-push rebase. Linux, Node 26.12.1, exclusive benchmark slot, simultaneous interleaved CPUs, swapped placement. No production Gateway load was generated.Validation: the new ordering file (5 tests), shared sorting (9 tests), and existing session utilities (72 tests) pass. Formatting, focused type-aware lint, and the export-name guard pass. The owner test file took 9.85 s on the busy local host (2.36 s test time); the existing session-utils file took 536.38 s including its compiled-worker setup. An initial session-utils setup was invalidated by an edit during compilation; the fixed-source rerun passed. The eager-import closure, PR-wrapper source closure, and CI Node test-plan guards also pass (178 tests; 701.63 s total on this host). The lane's explicitly authorized fast-path proof uses owner measurements and PR CI; a ten-minute Gateway stress campaign is not claimed.
Paired owner measurements, controls, and tradeoffs
Three A/B pairs (two swapped slot-A pairs, then the predeclared extra pair in slot B after opposite-sign descending results); 7,500 sorts per arm/case. CPU is untraced process CPU, including GC. Four matched A/A pairs used the same workload and instrumentation.
Pinned descending CPU: −1.6% bounded / −8.0% full. Unpinned descending CPU: +1.9% (+5.93 µs/sort) bounded / +1.3% (+1.89 µs/sort) full; these small shifts are within identical-source controls, not established regressions. A/A bounded descending deltas: pinned +0.29%, +4.64%, −4.06%, +2.74%; unpinned +5.13%, +3.01%, +0.38%, −2.35%. Unpinned full-sort A/A deltas: +1.51%, +1.08%, +0.63%, −2.35%.
Tradeoff: this is not a universal speedup. Unpinned random inputs cost +3.7% bounded (+4.35 µs) / +2.7% full (+28.77 µs); pin-heavy bounded inputs reduce CPU 88–92% and allocation 96–98%. An eager preparatory scan was discarded because it added unnecessary work to unpinned lists.
Pair 1: maximum natural GC pause 0.325 → 0.221 ms; host 1-minute load 2.57–2.90. Base/candidate maximum RSS 890.0/212.8 MiB, sampled end-of-timing heap 247.1/34.7 MiB. GC by kind (1=minor, 4=major, 8=incremental), base
{'1': {'count': 3454, 'ms': 172.067}}, candidate{'1': {'count': 477, 'ms': 36.703}, '8': {'count': 1, 'ms': 0.221}}.Pair 2: maximum natural GC pause 0.490 → 0.228 ms; host 1-minute load 2.32–2.82. Base/candidate maximum RSS 847.7/203.9 MiB, sampled end-of-timing heap 236.2/34.7 MiB. GC by kind (1=minor, 4=major, 8=incremental), base
{'1': {'count': 3411, 'ms': 166.116}}, candidate{'1': {'count': 477, 'ms': 35.255}, '8': {'count': 1, 'ms': 0.228}}.Pair 3: maximum natural GC pause 0.505 → 0.211 ms; host 1-minute load 1.23–2.86. Base/candidate maximum RSS 862.5/208.8 MiB, sampled end-of-timing heap 236.6/35.0 MiB. GC by kind (1=minor, 4=major, 8=incremental), base
{'1': {'count': 3397, 'ms': 180.5}}, candidate{'1': {'count': 477, 'ms': 29.271}, '8': {'count': 1, 'ms': 0.211}}.No pause percentile is used as a gate. Owner GC deltas are far below +1 ms/operation. RSS/heap snapshots include effects of earlier allocation-sampling passes in the same process and are context only; this is not a retained-heap or whole-Gateway benchmark.