fix: [Capacitor] use HTTP NDJSON streaming as default#940
Conversation
🦋 Changeset detectedLatest commit: 8818366 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
In order to get some more context. I did a small benchmark which compared the various connection options' sync time on iOS and Android. The test setup involved measuring the time taken to do an initial sync of 10_000 basic rows. [Update] The initial test result posted in this comment was incorrect. This comment has been updated with valid values. The general sync performance for Capacitor on iOS is terrible when using Buffers. Android also has a substantial performance hit when using Buffers - however the impact in iOS is orders of magnitude worse than in Android. Legend:
Capacitor benchmark resultsThe differences between Android and IOS are too large to display in the same graph. OPFS seems to have issues on iOS due to opauge origins and security concerns. Note that the Kotlin SDKFor a comparison, the same data was synced using the Kotlin SDK. The time observed is in the realm of the NDJSON HTTP results seen above.
SummaryWhile there clearly are general issues when using Buffers, I think for now - using HTTP is the better option. |
simolus3
left a comment
There was a problem hiding this comment.
I'm happy with these changes. There's nothing we can do about binary parameters being so expensive, so switching to text makes sense.



closes: #904.
The Capacitor SDK currently extends the Web SDK - where we provide some additional functionality tailored to Capacitor ecosystem, such as a SQLite driver based of Capacitor Community SQLite.
Currently: In the Web SDK, and by extension Capacitor SDK, we default to connecting to the PowerSync service via WebSockets which provide binary data payloads. These payloads are passed to our Rust Core via a SQLite query parameter.
The Capacitor Community SQLite library has quite poor performance for handling binary query parameters. See the comment below for a basic benchmark comparison.
The results from benchmarking indicate that connecting to the PowerSync service via an NDJSON HTTP stream provides much better performance. The benefit is that we pass string JSON values to SQLite via Capacitor Community SQLite instead of binary Buffers.
This PR updates the defaults for Capacitor to use NDJSON based HTTP connections by default when using Capacitor Community SQLite. Capacitor apps are also web apps: in order to keep things consistent with the Web SDK, we default to Web Sockets on web. This may bring more confusion than it's worth - the change is currently focussed to only affect the use-case with poor performance issues.