Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in GCP by (19.7k points)
recategorized by

I have a simple Cloud Function in Firebase that takes JSON in an HTTP POST and saves it to a Firestore collection. It's allocated 512MB memory.

The performance of this cloud function is very poor. If executed continuously, the round trip varies from 200-600ms and if executed infrequently (that is every 5-10 mins) it can exceed up to 4-10 seconds. I understand the cold start problem, but on AWS I've never seen a cold start this slow, nor this frequent.

I'd appreciate any insight into how to speed up performance.

Below is the code:

'use strict';

const functions = require('firebase-functions');

const admin = require('firebase-admin');


const db = admin.firestore();

const express = require('express');

const bodyParser = require("body-parser");

const app = express();

app.use(bodyParser.urlencoded({ extended: false }));


// CORS Express middleware to enable CORS Requests.

const cors = require('cors');

app.use(cors({ origin: true }))'/submitResponse', (req, res) => {


  if (!


  const payload =;


  const responses = db.collection("responses")


    payload: payload,

    timestamp: admin.firestore.FieldValue.serverTimestamp()

  }).then(function(docRef) {

    console.log("Response written with ID: ",;



  .catch(function(error) {

      console.error("Error adding document: ", error);


}); = functions.https.onRequest(app);


1 Answer

+1 vote
by (62.9k points)
selected by
Best answer

What has worked for me and increased significantly the speed of firebase functions, was to update the location of my functions. I'm located in Europe so the default was initially set to us-central1. After updating to europe-west1 speed went from ~5 seconds to ~600ms. It's relatively easy to change the region as described here.I've just followed their example and I was ready to go. Hope when you implement these editions, it helps you too!

Browse Categories