Skip to content
Discussion options

You must be logged in to vote

✅ Production Strategy: 500ms → 60ms (80% improvement)

  1. Minimum Instances (Eliminates 90% cold starts)
    // firebase.json or index.js
    exports.sendEmail = functions
    .runWith({ minInstances: 3 }) // Keep 3 warm instances
    .https.onRequest(async (req, res) => {
    // Your code
    });

Cost: ~$5/month for 3 instances 24/7 [web:195]

  1. Lazy Module Loading (150ms → 50ms)

❌ Slow: Global imports
const admin = require('firebase-admin'); // Loads at cold start

✅ Fast: Lazy load inside handler
exports.handler = async (req, res) => {
const admin = await import('firebase-admin'); // Loads only when called
// ...
};

Impact: Defers Firebase SDK (120MB) until first request [web:196]

  1. Bundle Optimization (esbuild/we…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by constant-infinite
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
CA Q&A
Labels
None yet
2 participants