Articles, Blog

Minimizing cold start time (Firecasts)

November 9, 2019

You Might Also Like


  • Reply John Doe March 18, 2019 at 9:01 pm


  • Reply praful apuri March 18, 2019 at 9:33 pm


  • Reply General Watching March 18, 2019 at 9:59 pm

    Thanks this is helpful..

  • Reply Donat Hmm March 18, 2019 at 10:40 pm

    What are cloud functions

  • Reply Eli Oshinsky March 18, 2019 at 10:55 pm

    I've been waiting for this video to be released hoping that there would be new information here. Sadly there wasn't. It seems that Azure and AWS have the leg up in terms of cold start efficiency right now.
    The use of a module cache would greatly improve some of these issues. Plus I would rather pay the price to import a module once on cold start than every time the function is executed.
    Also, why is the source for functionA bundled with functionB?
    Why doesn't firebase support a JSON or even yaml file in place of index.js allowing for proper context segregation?
    Additionally, given a larger project using functions that import many local files, there is no clarification about whether bundling these files together would optimize cold start times

  • Reply Mobile Apps March 18, 2019 at 11:35 pm


  • Reply Paul Kubb March 19, 2019 at 12:24 am

    too late, i left away from firebase half a year ago just because of this.
    my app was using fb cloud functions and got cold start like 1 minute. and it happened over and over since it was not too many people using it. my functions turned to crap and got complaints. now none of my projects are using fb.

  • Reply Mariano Paulin March 19, 2019 at 12:56 am

    I realized a way to reduce cold starts significantly on big projects with cloud functions. It's a bit tricky, but works very well (reduces the size of code and dependencies that will be downloaded to run a function). First, create different folders for different functions that will use non-related node modules, make "npm init" on each folder and install the corresponding modules (note: firebase-functions will be installed in all folders) and create your index.js traditionally for each folder. The setup looks like this:


    To deploy the functions, clearly you need to do it separately for each folder. So, to deploy functions in "folder1", edit firebase.json with the next config:
    "functions": {
    "source": "folder1"
    And inside root-folder run "firebase deploy –only functions:functionName"
    IT'S SO IMPORTANT to write "–only functions:functionName" because if you don´t specify this, the functions already deployed will be erased!!
    Hope this will be useful

  • Reply Andika Tanuwijaya March 19, 2019 at 1:06 am

    aw last part of the series 🙁

  • Reply Bitter Lime March 19, 2019 at 1:32 am

    Indeed a very informative series.Thanks Doug! what's next on your list?

  • Reply Pravin Mane March 19, 2019 at 2:08 am

    Thank you sir for this video.. 😊

  • Reply Ian Jasper Santos March 19, 2019 at 4:03 am

    Firebase team please make a tutorial how to use firebase storage along with cloud function for firestore

  • Reply Denis TRUFFAUT March 19, 2019 at 5:44 am

    Excellent summary. Nice Typescript hint.
    Advices in this video are :
    1) Only use code you need inside functions. Shared code must be minimal. That's the whole philosophy of await import. Just like for PWAs, where each page dynamically imports only what it needs, in Cloud functions for Firebase, each function dynamically imports only what it needs.
    2) Don't make errors, or catch them, to avoid shutdown. Dealing with errors can have a huge impact, especially on repeated errors, that will constantly shutdown your functions instances, giving the worst performance.
    3) Only after implementing these optimizations, if needed, regularly ping (Google Cloud Scheduler) all your functions to keep them alive, at the cost of calling these functions.

  • Reply Martin Stangl March 19, 2019 at 7:13 am

    It was not explained explicitly, but I assume, the cold start time is added to the execution time of a function, if it is the first function to be executed on a new instance for the first time. And this is why we want to optimize cold start time.

    Just thinking loud: Would it not be an option to prepare a new instance ahead of time, so the global context is loaded, before actual work load is redirected to it for the first time? Then cold start time would have no impact on new instances.

  • Reply charafouddine ahmed March 19, 2019 at 8:03 am


  • Reply Regaïeg Zied March 19, 2019 at 12:11 pm

    How much time does the cold start take in general?

  • Reply David Carr March 19, 2019 at 1:26 pm

    Hi Doug, is there a full example of a script using these methods?

  • Reply The GameArena March 19, 2019 at 11:55 pm

    Any upcoming updates for Queries and data modeling?

  • Reply Jürgen Brandstetter March 21, 2019 at 9:55 am

    If my index.js imports 2 modules (each one represents a cloud function) and each modules has a couple of imports, will all imports, even of sub-modules, get imported when the index.js get loaded? Or is the cloud function compiler wise enough to only import those sub-modules for the required cloud function?

  • Reply Marcel Otten March 21, 2019 at 4:12 pm

    Is there a way to measure cold start times?

  • Reply abrar masum March 21, 2019 at 5:39 pm

    Hello Doug,
    I need a suggestion. I want to write all the firebase read and write functions on firebase cloud servers and call http functions from my android and ios app. Is this a bad idea? Some developers suggesting that it will slow my apps. is it true?

  • Reply Tom Medhurst June 8, 2019 at 9:24 am

    The real issue that's not being addressed is the cold start time needed to initialize functions and admin init. This needs to be improved

  • Reply benaloney June 30, 2019 at 7:03 am

    This guy is great at explaining things, reminds me of the "Engineering Guy" YouTube channel

  • Reply Nelson La Rocca July 26, 2019 at 7:04 am

    Great videos with very important tips ! Thanks

    Is there any github or whatever example about how to split index.js in multiple files holding different "trigger" functions ?

  • Reply johan Van Wambeke July 29, 2019 at 9:36 am

    `What a nice guy

  • Reply Matt Penner August 25, 2019 at 9:21 am

    There are lots of examples, including in the Firebase docs, where people are using Express in their functions to serve up an API. Wouldn't including Express add to the overhead and the time it takes to spin up and serve the function? Why not just write minimal functions? Or does Express not increase the cold-start yet offer additional benefits?

  • Reply Alberto Di Gioacchino September 30, 2019 at 1:34 pm

    Is the following google solution (friendlyPix) suffering from "heavy" cold start or not? Can we proceed this way to also keep cloud functions in different files?

  • Leave a Reply