How Netflix Uses AI Agents for Performance Engineering
Traditional performance engineering at Netflix heavily relied on an iterative, largely manual profiling process. Developers triggered profilers on production servers, analyzed complex flame graphs locally, mapped findings back to application code, and tested patches before redeploying. This labor-intensive workflow fails to scale because it depends on scarce domain experts with deep knowledge of low-level execution stacks. Consequently, teams can only prioritize major incidents or obvious slowdowns, leaving smaller, gradual resource drains undetected. The widespread adoption of AI coding assistants has led to increased software performance issues, driven primarily by the 'speed trap' and the 'context gap.' While developers can generate code up to ten times faster, this acceleration often results in code bloat, regressions, and long-term architectural maintenance. Furthermore, while large language models (LLMs) excel at localized logic and syntax, they lack critical visibility into runtime environments, call stacks, and peak-load resource constraints. Consequently, code that appears correct in isolation can lead to severe resource inefficiency when executed at scale. Netflix conducted an experiment to evaluate whether large language models (LLMs) can directly parse and interpret raw profiling data across diverse programming runtimes. Profilers across languages like Java, Python, and Go share core paradigms by breaking execution into call stacks and tracking metrics like inclusive time and self (CPU) time. Because LLMs have ingested extensive software repositories, they possess innate knowledge of standard anti-patterns such as quadratic loops and excessive allocations. Consequently, Netflix concluded that a unified analytical workflow can utilize LLMs to pattern-match call stacks against known performance issues.
Read the original ↗Contents
Bottlenecks For Traditional Performance Work
Traditional performance engineering at Netflix heavily relied on an iterative, largely manual profiling process. Developers triggered profilers on production servers, analyzed complex flame graphs locally, mapped findings back to application code, and tested patches before redeploying. This labor-intensive workflow fails to scale because it depends on scarce domain experts with deep knowledge of low-level execution stacks. Consequently, teams can only prioritize major incidents or obvious slowdowns, leaving smaller, gradual resource drains undetected.
- Traditional performance engineering at Netflix was primarily a manual, iterative loop.
- The process required developers to trigger profilers on live production servers, download trace data, and manually analyze flame graphs for high CPU or memory consumption.
- Developers had to manually inspect cryptic method names in codebase logic, locate inefficient operations, and propose patches.
- The traditional workflow does not scale because it requires scarce domain experts with deep low-level execution stack knowledge.
- Due to limited human attention, investigations are restricted to major incidents or evident slowdowns, allowing smaller continuous resource leaks to go unnoticed.
The Problem with AI Code
The widespread adoption of AI coding assistants has led to increased software performance issues, driven primarily by the 'speed trap' and the 'context gap.' While developers can generate code up to ten times faster, this acceleration often results in code bloat, regressions, and long-term architectural maintenance. Furthermore, while large language models (LLMs) excel at localized logic and syntax, they lack critical visibility into runtime environments, call stacks, and peak-load resource constraints. Consequently, code that appears correct in isolation can lead to severe resource inefficiency when executed at scale.
- AI coding assistants cause software performance issues primarily through the 'speed trap' and the 'context gap'.
- Developers can generate and ship code up to 10 times faster with AI tools, but fast generation does not ensure runtime performance.
- Rapid AI-assisted code generation frequently introduces technical debt such as debugging regressions and code bloat.
- LLMs produce syntactically correct code that passes unit tests but lacks awareness of host runtime environments and critical execution paths.
- Code generated by AI in isolation can severely waste system resources when run at platform scale.
Can LLMs Handle Profile Data
Netflix conducted an experiment to evaluate whether large language models (LLMs) can directly parse and interpret raw profiling data across diverse programming runtimes. Profilers across languages like Java, Python, and Go share core paradigms by breaking execution into call stacks and tracking metrics like inclusive time and self (CPU) time. Because LLMs have ingested extensive software repositories, they possess innate knowledge of standard anti-patterns such as quadratic loops and excessive allocations. Consequently, Netflix concluded that a unified analytical workflow can utilize LLMs to pattern-match call stacks against known performance issues.
- Netflix evaluated whether LLMs could automate the analysis of raw runtime profiling data.
- Profilers across different languages (such as JVM's async-profiler, Python's py-spy, and Go's pprof) share core structures by decomposing execution into call stacks with inclusive and self CPU time metrics.
- A single analytical pipeline can theoretically process profiling data from nearly any programming runtime due to these shared profiler foundations.
- Pretrained LLMs already understand classic programming anti-patterns, including loop invariants, quadratic complexity, and excessive memory allocations on hot paths.
- Engineering workflows can prompt LLMs to pattern-match known performance bugs directly against observed call stacks instead of guessing performance bottlenecks from scratch.
The Agentic Profiling Pipeline
Netflix developed an automated performance profiling system that integrates a large language model within a defined pipeline. During implementation, engineers discovered that feeding unconstrained raw stack traces causes the model to waste reasoning tokens on low-level routines such as JVM garbage collection pauses, Linux kernel syscalls, and third-party library overhead. Because application developers cannot control these platform-level operations, the system enforces strict package prefix rules. This scoping strategy allows the agent to filter out background platform noise and focus strictly on actionable application code.
- Netflix implemented an automated performance profiling pipeline that wraps an LLM.
- Providing raw, unbounded stack traces causes LLMs to waste reasoning tokens analyzing low-level platform noise.
- Unfiltered traces distract models with JVM garbage collection pauses, Linux kernel syscalls, and third-party framework overhead.
- Developers generally cannot modify underlying library internals or operating system routines.
- Applying strict package prefix rules directs the agent to focus solely on user application code.
The Problems Netflix Found in Production
When Netflix deployed an automated profiling agent against its production services, it identified four major categories of performance bugs. These bottlenecks included quadratic algorithmic complexity in Java Streams reduction, excessive regular expression evaluations on hot paths, and redundant object allocations causing out-of-memory risks. Additionally, the agent discovered metric registry lookup misuse that consumed up to 66% of CPU time due to synchronization locks. Across all cases, the agent optimized the code via approaches like single-pass collections, lookup tables, and cached references.
- Repeatedly copying an ImmutableMap inside a Java Stream reduction caused O(N^2) complexity and consumed 8.8% of CPU resources.
- Evaluating dynamic regex string sanitization on high-volume traffic consumed 46% of service CPU; switching to a pre-computed lookup table was 22 times faster.
- Creating a new HashSet on every incoming request accounted for 47% of total heap collections and contributed to out-of-memory crashes.
- Looking up metric counters repeatedly from a registry incurred dictionary lookups and synchronization locks that consumed 66% of CPU, compared to just 0.3% for actual business logic.
- Caching the metric counter reference during class initialization resolved the telemetry overhead across three separate services.
Safety, Verification, and Trust Architecture
Deploying code optimizations generated by AI agents directly into production introduces serious risks of business logic regression. To mitigate this, an agentic pipeline incorporates a four-stage standard software development lifecycle (SDLC) safety framework. The process starts with automated logic verification through unit, integration, and contract testing, followed by a side-by-side production canary deployment. Telemetry metrics such as latency and CPU utilization are strictly gathered without AI evaluation, concluding with a human developer making the final merge decision via a pull request.
- AI-driven code optimizations require rigorous automatic verification to prevent breaking core business logic.
- Stage 1 requires the agent's branch to pass all existing unit, integration, and contract tests before proceeding.
- Stage 2 uses a production canary deployment that receives partial traffic alongside an identical baseline running the original code.
- Stage 3 collects hard telemetry metrics (CPU utilization, median/P99 latency, memory allocation) without using an AI model to evaluate canary results.
- Stage 4 requires a human developer to review a pull request containing the code, original flame graph, and canary report to make the final deployment decision.
Shifting Left
Relying strictly on automated production profiling introduces issues like wasted compute costs, developer hesitation to alter running services, and redundant debugging across teams. To address this, Netflix shifted performance checks left into earlier development stages and implemented a shared memory mechanism across their agents. Because LLMs are inherently stateless, Netflix created a Pattern Catalog using a simple Git repository with plain Markdown files to maintain persistence across the organization. This catalog serves as a centralized, human-reviewable source of truth that easily injects into LLM prompts across multiple environments without needing complex vector databases.
- Detecting performance anti-patterns solely in production leads to wasted compute costs and developer reluctance to modify stable, running services.
- Netflix shifted performance profiling left into early development cycles to prevent redundant issues across different teams.
- Because LLMs are stateless, Netflix paired them with a stateful Pattern Catalog to provide a shared memory across services.
- The Pattern Catalog was designed to be centralized, compatible across environments (CI/CD, local, offline), easily injectable into system prompts, and human-reviewable.
- Instead of using complex vector databases, Netflix implemented the Pattern Catalog via a standard Git repository containing Markdown files, inspired by Andrej Karpathy's 'LLM-wiki' concept.
How Netflix Catches Problems Early
Netflix manages performance engineering through two complementary workflows powered by a centralized Pattern Catalog: a reactive path and a proactive path. In the reactive path, automated agents profile production services, test candidate fixes on canary instances, and update the catalog with new bottleneck patterns. In the proactive path, CI tooling scans pull requests against the catalog using regex and symbol matching to identify anti-patterns early. When a match is found, an LLM evaluates the pull request diff and leaves inline comments explaining the inefficiency, calculating resource impact, and proposing fixes before merge.
- Netflix divides performance engineering into a reactive profiling pipeline and a proactive pre-merge detection pipeline.
- Both performance workflows rely on a shared repository of known issues known as the Pattern Catalog.
- The reactive pipeline tests automated fixes on canary instances before updating the Pattern Catalog with verified findings.
- The proactive pipeline checks pull requests against cataloged anti-patterns via fast regex or symbol indexing in CI.
- When anti-patterns are flagged, an LLM analyzes the PR diff to provide inline feedback on inefficiency, resource costs, and remediation.
Conclusion
Automating performance engineering does not need to be an all-or-nothing effort, as demonstrated by Netflix's engineering practices. Organizations can progress across a four-level maturity spectrum ranging from purely manual performance analysis to fully autonomous AI agents. Netflix currently operates at Level 2, utilizing orchestration, proactive scanning, and a Pattern Catalog. Their long-term vision is Level 3, where autonomous agents independently create optimization strategies and run automated benchmarks.
- Performance engineering automation follows a four-level maturity spectrum rather than an all-or-nothing approach.
- Level 0 relies entirely on manual developer effort for capturing traces and interpreting flame graphs without machine learning.
- Level 1 uses LLMs as analytical copilots to identify hot execution paths from developer-provided stack dumps.
- Level 2 represents Netflix's current state, involving orchestration, proactive scanning, and the Pattern Catalog.
- Level 3 is Netflix's future goal, aiming for autonomous agents that develop optimization strategies, explore alternative implementations, and execute benchmarks.