Measuring total cold start time tells you how bad the problem is, not what is causing it. If your Node.js Lambda has a 2-second cold start, you need to know whether the bottleneck is aws-sdk import (400ms), database pool init (800ms), or framework startup (600ms). LLRT, X-Ray init tracing, and lazy loading techniques reveal the exact cause so you fix the right thing. This guide focuses on AWS Lambda cold start, with the production trade-offs senior engineers need to make sound decisions.
⚡ TL;DR: Use X-Ray subsegments to measure individual init operations. Lazy-load heavy dependencies inside the handler instead of at module scope. LLRT (AWS low-latency runtime) reduces Node.js cold starts 70-80% for I/O-bound functions. Use CloudWatch Insights to measure p99 cold start distribution over time.
LLRT — AWS low-latency JavaScript runtime — AWS Lambda cold start
# LLRT (Low Latency Runtime) — released 2024
# Built on QuickJS instead of V8 — no JIT compilation = faster cold start
# Benchmarks vs Node.js 20 (same function, 512MB, us-east-1):
# Hello world: Node.js 180ms | LLRT 42ms (77% faster)
# AWS SDK v3 + DynamoDB: Node.js 480ms | LLRT 95ms (80% faster)
# Express.js API: Node.js 620ms | LLRT 210ms (66% faster)
# Trade-offs:
# + Cold starts 70-80% faster
# - Warm invocations 20-40% slower (no JIT warm-up)
# - Not all Node.js APIs supported (partial crypto, worker_threads)
# - Still experimental (Q1 2026)
# Deploy with LLRT:
Resources:
MyFn:
Type: AWS::Serverless::Function
Properties:
Runtime: provided.al2023
Layers:
- !Sub arn:aws:lambda:us-east-1:094274105915:layer:LLRTNodejs20:10
Handler: index.handlerX-Ray init tracing — measure individual init steps
// Wrap each init operation in an X-Ray subsegment
const AWSXRay = require("aws-xray-sdk-core");
const seg = AWSXRay.getSegment().addNewSubsegment("init");
const dbSeg = seg.addNewSubsegment("db-pool");
const pool = await createConnectionPool({ max: 10 });
dbSeg.close();
const schemaSeg = seg.addNewSubsegment("schema-load");
const schema = await loadSchema("/var/task/schema.json");
schemaSeg.close();
seg.close();
// X-Ray now shows:
// init (total: 1,240ms)
// db-pool: 820ms <- bottleneck
// schema-load: 180ms
// Now you know exactly what to optimizeLazy loading — the simplest cold start fix
// BEFORE: everything loads during cold start
const sharp = require("sharp"); // 400ms — even for non-image requests
const Jimp = require("jimp"); // 200ms
exports.handler = async (event) => {
if (event.action === "resize") return resizeImage(event, sharp);
return processData(event); // Still paid 600ms for unused imports
};
// AFTER: lazy load
let _sharp;
const getSharp = () => _sharp || (_sharp = require("sharp"));
exports.handler = async (event) => {
if (event.action === "resize") return resizeImage(event, getSharp());
return processData(event); // Cold start now 400ms faster
};
// AWS SDK v3 — import only what you need (tree-shakeable)
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { GetItemCommand } from "@aws-sdk/client-dynamodb";
// NOT: import * as AWS from "aws-sdk"; // v2 costs 300-500msCloudWatch Insights — cold start profiling queries
# Cold start distribution:
filter @type = "REPORT" and ispresent(@initDuration)
| stats percentile(@initDuration, 50) as p50,
percentile(@initDuration, 90) as p90,
percentile(@initDuration, 99) as p99,
count() as coldStarts
by bin(1h)
# Correlation: memory vs cold start duration:
filter @type = "REPORT" and ispresent(@initDuration)
| parse @message "Memory Size: * MB" as memMB
| stats avg(@initDuration) as avgInit by memMB
| sort memMB asc- ✅ Use X-Ray init subsegments to find the exact bottleneck in your cold start
- ✅ Lazy-load heavy dependencies (image libs, ML models, large schemas)
- ✅ Use LLRT for I/O-bound Node.js functions where warm performance is secondary
- ✅ Import only specific exports from AWS SDK v3 — never import * from aws-sdk
- ✅ Measure p99, not just average — outlier cold starts cause user-visible latency
- ❌ Never import entire AWS SDK v2 at module scope — costs 300-500ms
Cold start profiling leads directly to Lambda Power Tuning — once you identify which init step is slow, tuning memory gives it more CPU. For Java cold starts, SnapStart eliminates the init bottleneck entirely. Official reference: LLRT GitHub repository.
Master AWS Lambda
→ AWS Solutions Architect Course on Udemy — The most comprehensive AWS course covering Lambda, serverless patterns, and production architecture.
→ AWS Certified Solutions Architect Study Guide — Deep Lambda chapter covering cold starts, VPC, layers, and SnapStart.
Sponsored links. We may earn a commission at no extra cost to you.
Free Weekly Newsletter
🚀 Don’t Miss the Next Cheat Code
You just read something most developers never learn. Get more secrets like this delivered every week — JavaScript internals, Python optimizations, AWS architectures, system design, and AI workflows.
Join 1,000+ senior developers who actually level up. Zero fluff, pure signal.
Related: Hidden AWS Lambda Cold Start Fix – Zero Cost, Zero Latency · Lambda in VPC Without the 10-Second Cold Start: The Fix Most Teams Missed · Lambda ADOT vs Powertools: Tracing Tradeoffs on Node 20 Runtimes
Watch: 100 Days of AI on YouTube
Short videos from CheatCoders, one AI engineering topic per day.
Most viewed
- Python Decorators Explained: From Simple Wrappers to Production Patterns
- Claude Code vs Cursor vs GitHub Copilot: Choose by Workflow, and Set Up One Repo That Works With All Three
- AI Agent Frameworks in 2025: LangGraph vs CrewAI vs AutoGen vs Raw API
- Python String Methods: Every str Method With Real Production Examples
- REST API Design Best Practices: The Patterns That Make APIs a Joy to Use
Newly added
- AWS Systems Manager Parameter Store: Hierarchical Runtime Config for Coding Agents
- Amazon Cognito Identity Pools: Federate Coding-Agent Tool Callers Without Long-Lived Keys
- Amazon Athena for Coding Agents: Query Tool Audit Logs and Eval Traces on S3 Without a Warehouse
- AWS Batch for Coding Agents: Parallel Overnight PR Reviews and Long-Running Jobs Without Lambda Timeouts
- Amazon Bedrock Prompt Management: Version and A/B Test Coding-Agent System Prompts
Deep-dive PDF
Get the expanded guide for this post — extra diagrams-style checklists, failure modes, and a production walkthrough. Free when you subscribe to CheatCoders.
Already subscribed? or open the subscribe page.
Discover more from CheatCoders
Subscribe to get the latest posts sent to your email.
