Skip to content

firestore: add experimental option "sendWriteRequestsDelayMs" to enable write request batching in fewer http requests #8895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

dconeybe
Copy link
Contributor

@dconeybe dconeybe commented Apr 3, 2025

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

@dconeybe dconeybe self-assigned this Apr 3, 2025
Copy link

changeset-bot bot commented Apr 3, 2025

⚠️ No Changeset found

Latest commit: 74d6f2e

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

Copy link
Contributor

github-actions bot commented Apr 3, 2025

Vertex AI Mock Responses Check ⚠️

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

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Apr 3, 2025

Size Report 1

Affected Products

  • @firebase/firestore

    TypeBase (1df3d26)Merge (8afab38)Diff
    browser382 kB383 kB+1.67 kB (+0.4%)
    main591 kB594 kB+2.88 kB (+0.5%)
    module382 kB383 kB+1.67 kB (+0.4%)
    react-native382 kB384 kB+1.67 kB (+0.4%)
  • @firebase/firestore-lite

    TypeBase (1df3d26)Merge (8afab38)Diff
    browser113 kB114 kB+968 B (+0.9%)
    main155 kB157 kB+1.34 kB (+0.9%)
    module113 kB114 kB+968 B (+0.9%)
    react-native113 kB114 kB+968 B (+0.9%)
  • bundle

    15 size changes

    TypeBase (1df3d26)Merge (8afab38)Diff
    firestore (CSI Auto Indexing Disable and Delete)272 kB274 kB+1.41 kB (+0.5%)
    firestore (CSI Auto Indexing Enable)272 kB274 kB+1.41 kB (+0.5%)
    firestore (Persistence)304 kB305 kB+1.41 kB (+0.5%)
    firestore (Query Cursors)250 kB251 kB+1.03 kB (+0.4%)
    firestore (Query)248 kB249 kB+1.03 kB (+0.4%)
    firestore (Read data once)236 kB237 kB+1.03 kB (+0.4%)
    firestore (Read Write w Persistence)328 kB330 kB+1.41 kB (+0.4%)
    firestore (Realtime updates)238 kB239 kB+1.03 kB (+0.4%)
    firestore (Transaction)215 kB216 kB+1.03 kB (+0.5%)
    firestore (Write data)214 kB216 kB+1.41 kB (+0.7%)
    firestore-lite (Query Cursors)104 kB105 kB+844 B (+0.8%)
    firestore-lite (Query)99.9 kB101 kB+844 B (+0.8%)
    firestore-lite (Read data once)75.4 kB76.2 kB+844 B (+1.1%)
    firestore-lite (Transaction)101 kB101 kB+844 B (+0.8%)
    firestore-lite (Write data)85.0 kB85.8 kB+844 B (+1.0%)

  • firebase

    TypeBase (1df3d26)Merge (8afab38)Diff
    firebase-compat.js794 kB796 kB+1.29 kB (+0.2%)
    firebase-firestore-compat.js340 kB341 kB+1.29 kB (+0.4%)
    firebase-firestore-lite.js131 kB132 kB+962 B (+0.7%)
    firebase-firestore.js440 kB442 kB+1.67 kB (+0.4%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/qhRIt5a53G.html

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Apr 3, 2025

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

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/yuHB84Eq6d.html

@dconeybe dconeybe changed the title firestore: let mutations accrue for 250ms and send them in batches firestore: add experimental option "sendWriteRequestsDelayMs" to enable write request batching in fewer http requests Apr 7, 2025
@dconeybe
Copy link
Contributor Author

dconeybe commented Apr 9, 2025

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.

@tormjens
Copy link

@dconeybe This is great news. Thank you for your efforts here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(Firestore) Grouped HTTP requests while in offline mode
3 participants