firestore: add experimental option "sendWriteRequestsDelayMs" to enable write request batching in fewer http requests
This is a proposed fix to reduce the number of HTTP POST requests sent from the browser when the write pipeline is being replenished after each write acknowledgement. This is done by batching writes into a single HTTP request that get added into the pipeline due to fast write acknowledgements within a 250ms window. This fix is subject to change or being reverted entirely. It needs thorough review and testing.
Fixes: #5971
⚠️ No Changeset found
Latest commit: 74d6f2e75635a0aade30c1b702d5d98dca93789d
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
Vertex AI Mock Responses Check :warning:
A newer major version of the mock responses for Vertex AI unit tests is available. update_vertexai_responses.sh should be updated to clone the latest version of the responses: v8.0
Size Report 1
Affected Products
@firebase/firestoreType Base (1df3d26) Merge (8afab38) Diff browser 382 kB 383 kB +1.67 kB (+0.4%) main 591 kB 594 kB +2.88 kB (+0.5%) module 382 kB 383 kB +1.67 kB (+0.4%) react-native 382 kB 384 kB +1.67 kB (+0.4%) @firebase/firestore-liteType Base (1df3d26) Merge (8afab38) Diff browser 113 kB 114 kB +968 B (+0.9%) main 155 kB 157 kB +1.34 kB (+0.9%) module 113 kB 114 kB +968 B (+0.9%) react-native 113 kB 114 kB +968 B (+0.9%) bundle15 size changes
Type Base (1df3d26) Merge (8afab38) Diff firestore (CSI Auto Indexing Disable and Delete) 272 kB 274 kB +1.41 kB (+0.5%) firestore (CSI Auto Indexing Enable) 272 kB 274 kB +1.41 kB (+0.5%) firestore (Persistence) 304 kB 305 kB +1.41 kB (+0.5%) firestore (Query Cursors) 250 kB 251 kB +1.03 kB (+0.4%) firestore (Query) 248 kB 249 kB +1.03 kB (+0.4%) firestore (Read data once) 236 kB 237 kB +1.03 kB (+0.4%) firestore (Read Write w Persistence) 328 kB 330 kB +1.41 kB (+0.4%) firestore (Realtime updates) 238 kB 239 kB +1.03 kB (+0.4%) firestore (Transaction) 215 kB 216 kB +1.03 kB (+0.5%) firestore (Write data) 214 kB 216 kB +1.41 kB (+0.7%) firestore-lite (Query Cursors) 104 kB 105 kB +844 B (+0.8%) firestore-lite (Query) 99.9 kB 101 kB +844 B (+0.8%) firestore-lite (Read data once) 75.4 kB 76.2 kB +844 B (+1.1%) firestore-lite (Transaction) 101 kB 101 kB +844 B (+0.8%) firestore-lite (Write data) 85.0 kB 85.8 kB +844 B (+1.0%) firebaseType Base (1df3d26) Merge (8afab38) Diff firebase-compat.js 794 kB 796 kB +1.29 kB (+0.2%) firebase-firestore-compat.js 340 kB 341 kB +1.29 kB (+0.4%) firebase-firestore-lite.js 131 kB 132 kB +962 B (+0.7%) firebase-firestore.js 440 kB 442 kB +1.67 kB (+0.4%)
Test Logs
Size Analysis Report 1
This report is too large (297,347 characters) to be displayed here in a GitHub comment. Please use the below link to see the full report on Google Cloud Storage.Test Logs
I did a quick performance test to see if there were any overall improvements to batching the write requests into fewer physical http requests. tl;dr there were only improvements noted on very slow ("3G") networks; the benefit on high-quality networks is negligible.
To test this I called disableNetwork(), called setDoc() 30 times, then called enableNetwork(). I tested by throttling the network connection in Chrome Developer Tools to the network profiles "4G (slow)" and "3G". Here are the results:
4G (slow)
Without batching: 2.4 seconds With batching: 2.8 seconds Batching improved runtime by 0.4 seconds (14% improvement)
3G
Without batching: 6.7 seconds With batching: 5.8 seconds Batching improved runtime by 0.9 seconds (13% improvement)
Not surprisingly, it seems that the slower the network the greater the benefit of batching. An improvement of almost 1 second in 3G networks could be quite noticeable to a person sitting there waiting for operations to complete. This improvement would be magnified as the number of write requests increases and as the network performance decreases.
@dconeybe This is great news. Thank you for your efforts here.