Why Is My Firebase Cloud Function Slow on the First Call? 6 Cold Start Fixes for Flutter Apps (2026)

By giosaia (GSPTeck) · Published 2026-10-19 · Last verified 2026-10-19

Why is my Firebase Cloud Function slow on the first call?

Almost always because of a cold start. By default Cloud Functions for Firebase scales the number of instances with traffic, “potentially scaling down to zero instances in times of reduced traffic,” so the first request after a quiet spell has to start a new instance, load your code and its modules, and run your global initialisation before your handler even begins. Firebase’s own tips page says cold starts “can take significant amounts of time to complete.” In an indie Flutter app with low, spiky traffic that is the normal case, not an edge case. Below: how to confirm it, then six fixes ordered from free to paid.

Confirm it is a cold start, not something else

Four checks to confirm a Cloud Functions cold start from a Flutter app: time two calls in a row, log at module load and in the handler, compare the first and second call, rule out region, queries and awaits
Confirm the cold start.

Measure before you change anything. Three quick checks:

  1. Time two calls in a row from Flutter. Wrap the callable in a Stopwatch and call it twice, a few seconds apart, after the app has been idle. If the first call is much slower and the second is fast, that gap is your cold start.
  2. Log at module load. Put a log line with a timestamp at the top of your functions file and another at the start of the handler. On a cold start you see both; on a warm call only the second. The gap between them is your own initialisation cost.
  3. Rule out the usual suspects. If every call is slow, look at the handler instead: unindexed queries, sequential awaits, or a function deployed in a region far from your users or your Firestore database.

If you already run Performance Monitoring in the app, our weekly Performance Monitoring triage routine shows where a slow network trace for a callable shows up.

The six fixes at a glance

FixCostEffortBest for
1. Lazy-load globalsFreeLowClients and SDKs only some functions use
2. Trim and defer importsFreeLow to mediumOne big index file exporting many functions
3. Use 2nd gen concurrencyFreeLowBursts of users at the same moment
4. Deploy in the right regionFreeMedium (redeploy)Every call, warm or cold
5. Minimum instances on one functionPaid while idleLowOne latency-critical callable
6. Hide the rest in the Flutter UIFree to lowLowWhatever latency remains

Fix 1: lazy-load globals that only some functions need

Global scope runs on every cold start. Firebase’s tips page shows the pattern: declare a variable globally but initialise it only “if (and when) the function is called.” Keep the Admin SDK initialisation global, because nearly every function uses it, and move anything heavier behind a lazy check: a payment client, an image library, a PDF generator. Google’s Cloud Run tips give the same advice and name the trade-off: lazy initialisation shifts that cost to the first request that needs it, so do it for objects used rarely, not for the ones every request touches.

Fix 2: trim and defer imports

Two columns contrasting a heavy functions index file that imports every SDK at the top with a light one that lazy-loads clients and defers big imports to the handler that needs them
Heavy versus light cold start.

In a Node.js codebase, every function exported from index.js loads every module that file imports at the top. One large SDK imported for a single admin function slows the cold start of all the others. Google’s guidance for dynamic languages is to “minimize the number and size of dependencies” and to lazily load code that is infrequently used. In practice:

Secrets count too: function instances read their bound secrets on every cold start, which our guide to Secret Manager rotation for Cloud Functions covers.

Fix 3: let one instance serve many requests

1st gen functions handle one request per instance, so a burst of ten simultaneous users can mean ten cold starts. In 2nd gen functions one instance can serve several requests at once; Firebase’s upgrade guide says “by default, concurrency is set at 80, but you can set it to any value from 1 to 1000.” If you still have 1st gen functions behind your Flutter app’s busiest screen, upgrading them is often the largest free win. Firebase’s tips page warns against setting concurrency low without a reason, because limiting it “incurs more cold starts.”

Fix 4: deploy close to your users and your database

Grid comparing six cold start fixes by cost: lazy globals, trimmed imports, 2nd gen concurrency of 80 by default, region near Firestore, minInstances billed at idle rates, Flutter warm-up
Six fixes by cost.

Region does not change how often cold starts happen, but it adds round-trip time to every call. Firebase’s locations page says the primary considerations “should be latency and availability” and to account for where your other services run: a Firestore database in the eur3 multi-region maps to functions in europe-west1, and nam5 maps to us-central1. In Flutter, a function outside the default region must be called through FirebaseFunctions.instanceFor(region: 'europe-west1'); forgetting this sends the call to the wrong region.

Fix 5: minimum instances, on one function only

Setting minInstances keeps instances warm. Firebase is clear about the price: warm instances “incur billing costs at idle rates,” about $3 a month for a 1st gen function with 256 MiB, or about $8 a month with 1 CPU and concurrency enabled, and the Firebase CLI shows an estimate when you deploy. It also does not remove cold starts: “if Cloud Functions for Firebase scales your app above your setting, you’ll experience a cold start for each instance above that threshold.”

Fix 6: hide what is left in the Flutter UI

Four Flutter UI tactics to hide remaining cold start latency: warm the function when the screen opens, show progress on tap, set a realistic callable timeout, show a friendly retry message
Hide what is left.

After fixes 1 to 4, a rare cold start may still cost a moment. You can make it invisible:

For the wider release checklist these fit into, see our guide to shipping Flutter and Firebase apps as an indie developer. The apps we build this way are listed on the GSPTeck apps and projects homepage.

Vertical Pinterest graphic listing six fixes for a slow first Firebase Cloud Function call in a Flutter app
Pinterest pin: six cold start fixes.

FAQ

How do I stop Firebase Cloud Functions cold starts completely?

You cannot remove them completely. Minimum instances reduce them, but Firebase notes you still get a cold start for each instance above your minimum. Combine lazy loading, lighter imports and concurrency to make each cold start shorter and rarer.

Does minInstances cost money even with no traffic?

Yes. Warm instances are billed at idle rates, about $3 a month for a 1st gen function with 256 MiB or about $8 a month with 1 CPU and concurrency enabled, according to Firebase. The Firebase CLI shows an estimate at deploy time.

Are 2nd gen functions faster to cold start?

The main gain is fewer cold starts, not a shorter one. Because one 2nd gen instance can serve up to 80 requests at once by default, a burst of users needs far fewer new instances.

Why is every call slow, not only the first?

Then it is probably not a cold start. Check the function’s region against your users and your Firestore location, and look for slow queries or awaits run one after another inside the handler.

Sources