Your Edge Functions take seconds to cold-start Because the bundle imports too many npm packages

Your Supabase Edge Functions are slow on cold start because they import heavy npm packages like the full AWS SDK, moment.js, and lodash. Warm invocations are quick, but after a few minutes of idle the isolate is recycled, and the next request waits while Deno decompresses the ESZip bundle and re-initializes the entire dependency tree.

  • Target: cold starts under 500ms
  • Fix shipped in 30 days
  • Slow Current cold start time
  • Heavy npm imports inflating the bundle
  • <500ms Target cold start after optimization

How it shows up

For teams where Edge Function cold starts take seconds because of oversized bundles, unnecessary npm imports, and missing Deno-native alternatives. Cold starts are not a Supabase limitation. They are a bundle size and initialization problem you can fix.

What this sprint fixes

  • Multi-megabyte bundle from unnecessary npm imports (target: under 500KB)
  • Slow cold starts degrading user experience
  • Full SDK imports where only one method is used

Oversized bundles loaded on every cold start

You import the full AWS SDK for a single presigned URL that aws4fetch signs in a few KB. Moment.js for one date format the native Temporal API now covers. All of Lodash for a single array operation. Deno decompresses and initializes the entire ESZip bundle on cold start, and every unnecessary byte adds latency.

Monolithic functions: one function loads every dependency

Your main Edge Function handles many different operations and imports every dependency for all of them on every cold start, even though each invocation uses only one. Supabase recommends fat functions, but that only works when imports are lean. We either split the heavy outliers out or lazy-load their dependencies so a typical request stops paying for code it never runs.

Direct DB connections: new handshake per invocation

Each Edge Function invocation opens a fresh direct database connection instead of borrowing one from the pool. The TCP and TLS handshake adds latency to every call, and a burst of invocations can exhaust Postgres connection limits outright. Routing through Supavisor in transaction mode on port 6543 reuses warm backend connections and is the pooling mode Supabase recommends for serverless and edge workloads.

Who it is for

Best fit when your users experience visible delays on API calls that hit Edge Functions after idle periods.

Good fit

  • Teams with Edge Function cold starts measured in seconds
  • Products where Edge Functions handle user-facing API calls
  • Applications that imported Node.js patterns into Deno without adaptation

Why Edge Function performance keeps getting deferred

Warm invocations are fast, so the team only notices the problem when users complain after idle periods.

Repeated failure patterns

  • Developers test with warm functions and never see the cold start in local development
  • The team imports npm packages by habit without checking for Deno-native or web-standard alternatives
  • Cold starts are intermittent, so the issue is hard to reproduce and deprioritized

What we do in 30 days

We profile every function, replace heavy imports, trim per-invocation dependency loading, and move database access onto Supavisor transaction-mode pooling.

  1. Days 1-5: Profiling

    Profile every Edge Function: measure cold start, warm invocation, bundle size, and dependency tree. Identify the 5 imports contributing most to cold start time. Rank by user impact.

  2. Days 6-14: Dependency optimization

    Replace heavy npm imports with Deno-native and web-standard alternatives. AWS SDK replaced with a focused aws4fetch presign utility (a few KB). Moment.js replaced with the native Temporal API, now stable in the Deno runtime. Proof release target: cold starts under 800ms.

  3. Days 15-24: Architecture optimization

    Split the heavy outlier operations out of monolithic functions and lazy-load the rest so typical invocations stay lean. Route database access through Supavisor in transaction mode on port 6543. Add response caching for idempotent operations.

  4. Days 25-30: Pre-warming and monitoring

    Implement pre-warming for critical user-facing paths. Set up latency monitoring with cold start tracking. Handoff with performance guidelines for future Edge Functions.

What you get

Every optimization measured with before/after production timing data.

Performance improvements

  • Target: cold starts under 500ms
  • Bundle size under 500KB (down from megabytes)
  • Target: warm invocations under 50ms

Monitoring and guidelines

  • Cold start and latency monitoring dashboard
  • Pre-warming configuration for critical paths
  • Performance guidelines for future Edge Function development

Why Pineido

We know Deno internals and Supabase infrastructure.

Deno-native expertise

We do not just strip npm packages. We replace them with Deno-native and web-standard alternatives that work with the Edge Function runtime. The AWS SDK presign call becomes a few KB of aws4fetch on top of fetch and SubtleCrypto. The replacement for moment.js is effectively 0KB because the native Temporal API is now stable in Deno.

The questions that decide if we are right for you

How do you reduce cold start time?

Three levers: reduce ESZip bundle size by replacing npm packages with Deno-native and web-standard alternatives, trim per-invocation dependency loading so a function only initializes the code a request actually uses, and route database access through Supavisor transaction-mode pooling to eliminate handshake overhead. Most of the improvement comes from the first lever.

Should we move off Edge Functions entirely?

Almost never. The performance issues are caused by how you use Edge Functions, not by the platform itself. The Deno runtime decompresses an ESZip bundle on cold start, so a lean bundle starts fast. Properly optimized Edge Functions cold-start in well under a second and warm-invoke in tens of milliseconds. That is fast enough for nearly any user-facing API call. We migrate only when a workload genuinely needs long-running compute, which Edge Functions are not built for.

Will replacing npm packages break our code?

The replacements are API-compatible wrappers or native equivalents, for example aws4fetch for AWS signing and the native Temporal API for date handling. We write the same test suite against both implementations and verify identical output before switching. Your application code changes minimally. The imports change, but the function signatures stay the same.

Can you optimize Edge Functions without changing our deployment process?

Yes. The optimizations happen at the code and configuration level: ESZip bundle reduction, leaner per-invocation imports, and Supavisor transaction-mode pooling. Your deployment pipeline stays the same. We deliver the changes as pull requests that go through your normal review process.

How do you measure performance improvement?

We instrument every function with timing data before and after. Cold start, warm invoke, p50, p95, and p99 latencies are all tracked. You see a before-and-after dashboard with real production data, not synthetic benchmarks.

What happens when Supabase updates Deno or the Edge runtime?

Our optimizations use stable Deno APIs and web standards like fetch, SubtleCrypto, and Temporal that are forward-compatible. When Supabase upgrades the Deno runtime, your functions inherit the improvement without rework. We document every dependency and every replacement so your team knows exactly what was changed and why.

Slow Current cold start time

Fix your Edge Function cold starts in 30 days

Target: under 500ms, down from seconds.

Fixed scope, fixed price.

You leave with

  1. We profile every Edge Function and identify the 5 heaviest imports
  2. Heavy npm packages replaced with Deno-native and web-standard alternatives by day 14

ByFounder and Imaginator

Published Updated