Edit: Removing irrelevant code to improve readability
Edit 2: Reducing example to only uploadGameRound function and adding log output with times.

I'm working on a mobile multiplayer word game and was previously using the Firebase Realtime Database with fairly snappy performance apart from the cold starts. Saving an updated game and setting stats would take at most a few seconds. Recently I made the decision to switch to using Firestore for my game data and player stats / top lists, primarily because of the more advanced queries and the automatic scaling with no need for manual sharding. Now I've got things working on Firestore, but the time it takes to save an updated game and update a number of stats is just ridiculous. I'm clocking average between 3-4 minutes before the game is updated, stats added and everything is available in the database for other clients and viewable in the web interface. I'm guessing and hoping that this is because of something I've messed up in my implementation, but the transactions all go through and there are no warnings or anything else to go on really. Looking at the cloud functions log, the total time from function call to completion log statement appears to be a bit more than a minute, but that log doesn't appear until after same the 3-4 minute wait for the data.

Here's the code as it is. If someone has time to have a look and maybe spot what's wrong I'd be hugely grateful!

**This function is called from Unity client:**

```
exports.uploadGameRound = functions.https.onCall((roundUploadData, response) => {

    console.log("UPLOADING GAME ROUND. TIME: ");
    var d = new Date();
    var n = d.toLocaleTimeString();
    console.log(n);

    //  CODE REMOVED FOR READABILITY. JUST PREPARING SOME VARIABLES TO USE BELOW. NOTHING HEAVY, NO DATABASE TRANSACTIONS.  //

    // Get a new write batch
    const batch = firestoreDatabase.batch();

    // Save game info to activeGamesInfo
    var gameInfoRef = firestoreDatabase.collection('activeGamesInfo').doc(gameId);

        batch.set(gameInfoRef, gameInfo);

        // Save game data to activeGamesData
        const gameDataRef = firestoreDatabase.collection('activeGamesData').doc(gameId);
        batch.set(gameDataRef, { gameDataCompressed: updatedGameDataGzippedString });

    if (foundWord !== undefined && foundWord !== null) {

        const wordId = foundWord.timeStamp + "_" + foundWord.word;

        // Save word to allFoundWords
        const wordRef = firestoreDatabase.collection('allFoundWords').doc(wordId);
        batch.set(wordRef, foundWord);

        exports.incrementNumberOfTimesWordFound(gameInfo.language, foundWord.word);

    }

    console.log("COMMITTING BATCH. TIME: ");
    var d = new Date();
    var n = d.toLocaleTimeString();
    console.log(n);

    // Commit the batch
    batch.commit().then(result => {
        return gameInfoRef.update({ roundUploaded: true }).then(function (result2) {

            console.log("DONE COMMITTING BATCH. TIME: ");
            var d = new Date();
            var n = d.toLocaleTimeString();
            console.log(n);

            return;
        });

    });

});

```

Again, any help with understanding this weird behaviour massively appreciated!