Witek
Witek

Reputation: 6462

Firestore runTransaction in Cloud Functions takes about 5 seconds on it's first call

After deployment of a Cloud Function, running a Firestore transaction always takes about 5 seconds. The time is lost between calling runTransaction and getting invoked inside the given transaction function.

It does not matter if anything happens inside the transaction or not.

After running the Cloud Function two times the 5 second delay disappears.

Is there any solution to this?

Upvotes: 1

Views: 335

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598728

Most likely this time is spent loading the SDK, and establishing the first route/connection to the servers. I doubt there's much you can do in your code about this.

You could consider using the Firestore Lite SDK, which is a lot smaller and thus loads faster. It doesn't support a local disk cache nor realtime listeners, but in Cloud Functions those are unlikely to matter.

Upvotes: 2

Related Questions