Skip to content

Fix Apple queued write throughput (#271) - #281

Draft
fotiDim wants to merge 2 commits into
mainfrom
fix/apple-write-queue-271
Draft

Fix Apple queued write throughput (#271)#281
fotiDim wants to merge 2 commits into
mainfrom
fix/apple-write-queue-271

Conversation

@fotiDim

@fotiDim fotiDim commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Fixes #271

  • Pipeline consecutive writes on iOS, macOS, and Chrome on Apple platforms without crossing queued operation barriers.
  • Add Darwin backpressure handling for writes without response and fail pending writes on disconnect.
  • Complete Darwin write-with-response callbacks FIFO to support pipelined writes safely.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves write throughput on Apple platforms by allowing consecutive BLE writes to be pipelined (submitted before prior writes complete) while preserving queue-barrier semantics for non-write operations. It also adds Darwin-side handling for write-without-response backpressure and ensures write-with-response callbacks resolve FIFO to safely support pipelined writes.

Changes:

  • Add a pipelining-capable queue path for writes (queueWrite + concurrent queue entries) while keeping non-write commands serialized behind write barriers.
  • Enable supportsWritePipelining on iOS/macOS implementations (Pigeon + Web) and use it in UniversalBle.write.
  • Update Darwin plugin to (a) backpressure writes without response, (b) fail pending writes on disconnect, and (c) resolve write-with-response futures FIFO; add tests + docs/changelog.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/universal_ble_write_queue_test.dart Adds regression tests for pipelined vs serialized writes and queue-barrier behavior.
test/universal_ble_test_mock.dart Extends the platform mock to satisfy the updated platform interface (readRssi).
README.md Documents Apple/Chromium-on-Apple pipelined write behavior and queue barriers.
lib/src/utils/ble_command_queue.dart Adds queueWrite and routes pipelined writes through concurrent queue adds.
lib/src/universal_ble.dart Uses queueWrite for write() and enables pipelining when the platform supports it.
lib/src/universal_ble_web/universal_ble_web.dart Enables write pipelining on iOS/macOS targets for Web implementation.
lib/src/universal_ble_pigeon/universal_ble_pigeon_channel.dart Enables write pipelining on iOS/macOS targets for native (Pigeon) implementation.
lib/src/queue.dart Adds addConcurrent and concurrency gating to allow consecutive concurrent items.
lib/src/interfaces/universal_ble_platform_interface.dart Introduces supportsWritePipelining capability flag (default false).
darwin/universal_ble/Sources/universal_ble/UniversalBlePlugin.swift Implements backpressure for write-without-response, disconnect failure for pending writes, and FIFO completion for write-with-response.
darwin/universal_ble/Sources/universal_ble/UniversalBleHelper.swift Adds PendingWriteWithoutResponse helper type.
CHANGELOG.md Notes the Apple pipelined write throughput improvement.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 433 to 436
guard let peripheral = deviceId.findPeripheral(manager: manager) else {
completion(Result.failure(createFlutterError(code: .deviceNotFound, message: "Unknown deviceId:\(self)")))
return
}
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.

[Bug]: QueueType global and perDevice degradation on Apple

2 participants