Skip to content

Reduce bounded observation backlog drain work - #64

Merged
jmonster merged 1 commit into
mainfrom
perf/bounded-observation-inbox
Sep 18, 2026
Merged

jmonster merged 1 commit into
mainfrom
perf/bounded-observation-inbox

Conversation

@jmonster

@jmonster jmonster commented Sep 17, 2026

Copy link
Copy Markdown
Owner

Bounded observation inbox optimization

Head: 5792b6d53ca2606e06d16b5c9252713c2136e610. Ready for review; all seven workflows for this unchanged head passed. Draft status has been removed. No PR merge or force-push was performed.

EventMailbox shifted the remaining pending array for every callback and rescanned it for obsolete envelopes. Draining a full 4096-envelope inbox performed quadratic backlog work under a mutex also used by the producer. The native pull reader also shifted its backlog on partial reads.

Use an internal specialized circular FIFO. Storage starts empty, grows geometrically to the unchanged configured bound, and immediately releases consumed envelopes/tokens. Ordered hub publication means obsolete envelopes after resynchronization form a prefix, rather than requiring a full scan.

Public Swift/C APIs, queue capacities, the single scheduled 32-event drain, queue/lock ownership, overflow/snapshot semantics and generation/retirement protections are unchanged. No dependency, public collection API, extra worker or telemetry is introduced.

Exact-head CI

Workflow Result
macOS package/regressions/app/demo PASS
Swift source/native C distribution PASS
Native SDL consumers PASS
Packaged runtime PASS
Swift concurrency PASS
SDL regressions PASS
Full emulator builds/inspections/GUI launches PASS

These are the workflows that ran for the unchanged head, not a claim that the newer Linux workflow ran on this older branch. The completion audit found no review comments, submitted change-request reviews or unresolved review threads. The downloaded CI source archive matches the complete published tree and executable modes.

Validation

The original local run passed complete retained regressions and 89 debug / 89 release package tests with warnings as errors. The seven new tests cover lazy bounded growth, non-power-of-two storage, 10,000 events at six capacities, wrapped partial reads, obsolete-prefix cleanup, immediate lifetime/snapshot-token release, overflow recovery and 12,285 ordered input deliveries. No existing assertion was removed or weakened.

Additional completion validation combined current main a187693b8ced4328758c4e242a4eb203d26608a2 with #63, #64, corrected #65 (4fef3dc) and corrected #68 (9757016). The local combined tree is fa80b2e7eab3dfadc3196e73c01c9d59079b1422; it was not published or merged.

  • Complete retained regressions and 92 debug / 92 release package tests with warnings as errors: PASS.
  • Twenty isolated BlueZ scenarios and 40 additional release transition cases: PASS with this optimized queue, including cancellation, delayed discovery/adapter switching, early acknowledgements and all four models.
  • Actual SDL 3.4.16/native host suite, including pinned Cemu and Dolphin motion processors: 8/8 PASS.
  • Native facade lib/lib64 relocation, two real C++ consumers and missing-library negative controls: PASS.
  • A separate local all-four-model harness exercised actual BlueZ transport → this shared queue/C ABI → unmodified SDL 3.4.16 → pinned Cemu motion, including motor requests, reconnect identity and teardown. PASS. This harness uses a synthetic service and explicit synthetic profiles, not physical controllers, and is not a newly committed CI test.

Recorded performance evidence

tests/observation-buffer/benchmark.sh measures nine release-mode resume-to-last-handler drain times after queuing the configured capacity and verifies delivery/completion. It is not a CI timing gate.

Envelopes Previous median Circular FIFO median
256 0.205 ms 0.103 ms
4096 41.966 ms 0.941 ms

A later original execution recorded 0.098 ms and 0.936 ms. These are queue-only measurements from the original Linux runner, not measured Bluetooth, gameplay or macOS latency. CPU load and scheduling affect results. No platform-wide speed guarantee, physical measurement, controller-capability change or calibration claim is introduced.

Replace EventMailbox and native pull-reader pending arrays with a private, lazily grown circular FIFO. Drop only the obsolete ordered prefix after resynchronization and release consumed envelope references immediately. The existing capacities, single scheduled drain, locks, generation/retirement checks and overflow/snapshot contracts are unchanged.

Retain all existing tests; add seven tests covering 10,000-event wraps across non-power-of-two and maximum capacities, lazy bounded allocation, token release, partial reads, overflow recovery and repeated full-rate hub backlogs. Add an optional actual-mailbox release microbenchmark without a CI timing threshold.

Linux validation: 89 package tests with warnings as errors and 6 real Swift/C/SDL/Cemu host CTests pass. The identical queue-only benchmark reduces 4096-envelope median drain time from about 42 ms to 0.94 ms on this runner; this is not controller latency or a platform guarantee. Native Apple-SDK and complete emulator qualification must run on the published head.
@jmonster
jmonster marked this pull request as ready for review September 18, 2026 00:38
@jmonster
jmonster merged commit 247868b into main Sep 18, 2026
19 checks passed
@jmonster
jmonster deleted the perf/bounded-observation-inbox branch September 18, 2026 01:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant