Improve Supabase Connector
In this tutorial we will show you how to improve the performance of the Supabase Connector for the React Native To-Do List demo app.
Background
The demos in the powersync-js monorepo provide a minimal working example that illustrate the use of PowerSync with different frameworks. The demos are therefore not necessarily optimized for performance and can therefore be improved.
This tutorial demonstrates how to improve the Supabase Connector’s performance by implementing two batching strategies that reduce the number of database operations.
Batching Strategies
The two batching strategies that will be implemented are:
- Sequential Merge Strategy, and
- Pre-sorted Batch Strategy
Differences
Key similarities and differences
Key Similarities
Handling of CRUD operations (PUT, PATCH, DELETE) to sync local changes to Supabase
Transaction management with getNextCrudTransaction()
Implement similar error handling for fatal and retryable errors
Complete the transaction after successful processing
Key Differences
Operation grouping strategy
Batching methodology
Use cases
Sequential Merge Strategy
You need more granular control over batch sizes
You want more detailed operation logging
You need to handle mixed operation types more efficiently
Best for: Mixed operation types
Optimizes for: Memory efficiency
Trade-off: Potentially more network requests
Pre-sorted Batch Strategy
You have a large number of similar operations.
You want to minimize the number of network requests.
Best for: Large volumes of similar operations
Optimizes for: Minimal network requests
Trade-off: Higher memory usage