Automated Performance Optimization with GenAI-Powered Code Analysis

uber · Tech · 2025 · source Agentic: no · promotional bias: med · source-backed · extracted with prompt 0.5.4 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: Software performance engineering

Uber needed to find and fix Go performance antipatterns across high-cost production services without relying on scarce compiler/runtime experts and multi-day manual profiling cycles.

Constraints:

Architecture

Uber built PerfInsights as a two-stage system. First, a fleet-wide profiler identifies the top 30 expensive Go functions during peak traffic, adds memory profiling when runtime.mallocgc exceeds 15% CPU time, and statically filters out OSS dependencies and runtime internals so only service-owned hotpaths remain. Second, a GenAI detector receives full source code plus a curated Go antipattern catalog and proposes optimizations. Few-shot prompts, Go-expert role framing, confidence scoring, LLM juries, and LLMCheck rule validators reduce hallucinations and false positives. Validated suggestions flow to downstream code transformation or manual review, and integration with Optix/CI turns performance tuning into a continuous workflow.

Diagram confidence: explicit (topology described by the source).

flowchart LR
  fleet-wide-profiler[Fleet-wide profiler] --> static-hotpath-filter[Static hotpath filter]
  static-hotpath-filter --> genai-antipattern-detector[GenAI antipattern detector]
  genai-antipattern-detector --> llm-jury[LLM jury]
  llm-jury --> llmcheck-validators[LLMCheck validators]
  llmcheck-validators --> optix-code-optimization[Optix code optimization]
  optix-code-optimization --> developer-review-workflow[Developer review workflow]
  developer-review-workflow --> llmcheck-dashboards[LLMCheck dashboards]
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Fleet-wide profiler Collects CPU and memory profiles from production Go services during peak traffic periods. Static hotpath filter
Static hotpath filter Selects top expensive service-owned functions and excludes OSS dependencies and runtime internals. Fleet-wide profiler, GenAI antipattern detector
GenAI antipattern detector Analyzes full Go function source against a curated antipattern catalog and suggests optimizations. Static hotpath filter, LLM jury
LLM jury Independently validates detected antipatterns and suggested optimizations with multiple LLM judgments. GenAI antipattern detector, LLMCheck validators
LLMCheck validators Run domain-specific rule validators to catch false positives and track detection accuracy metrics. LLM jury, Optix code optimization
Optix code optimization Receives validated suggestions for automated downstream code transformation. LLMCheck validators, Developer review workflow
Developer review workflow Lets engineers review or merge performance diffs and act on optimization suggestions. Optix code optimization, LLMCheck dashboards
LLMCheck dashboards Expose detection accuracy, error patterns, model regressions, and antipattern frequency. Developer review workflow

Data flow

Production CPU and memory profiles feed a static filtering step that selects expensive service-owned functions. PerfInsights sends each candidate function and an antipattern catalog to an LLM detector. The output is checked by LLM juries and LLMCheck validators, scored for confidence, and sent to code transformation or developer review. Metrics from LLMCheck dashboards track false positives, regressions, antipattern frequency, and code-health trends.

4 supporting quotes
“PerfInsights’ optimization pipeline consists of two main stages: profiling-based function filtering and GenAI-driven antipattern detection.”article, stated
“For each service, it identifies the top 30 most expensive functions based on flat CPU usage. This is based on the observation that the top 30 most expensive functions account for the majority of CPU usage.”article, stated
“PerfInsights passes their full source codes and a list of antipatterns to a large language model (LLM) for analysis.”article, stated
“The final output includes a confidence score of the function’s optimisability and suggested improvements. These insights are fed into downstream tools for code transformation or manual review by developers.”article, stated

Why this architecture

PerfInsights deliberately combines deterministic profiling/static filtering with LLM analysis because raw LLM scans over a monorepo would be noisy and costly. The profiler finds code paths worth optimizing, the static filter constrains the context to service-owned functions, and the LLM brings pattern-recognition ability to code-level antipattern detection. LLM juries and LLMCheck are separate trust layers because early single-shot attempts hallucinated and generated unreliable outputs.

4 supporting quotes
“Before any GenAI magic happens, PerfInsights performs aggressive static filtering using CPU and allocation profiles.”article, stated
“This pre-processing transformed what could have been a brittle AI prototype into a focused optimization assistant”article, stated
“In our initial attempts, a single-shot LLM-based antipattern detection produced inconsistent and unreliable results”article, stated
“A core strength of PerfInsights lies in its robust validation pipeline, which includes two complementary systems: LLM juries and LLMCheck.”article, stated

Models used: large language models · LLM juries · GenAI model

Scale

Alternatives considered (roads not taken)

Manual expert-led profiling and optimization

Rejected because: It required niche expertise and days, weeks, or months of effort that could not scale across services.

“Profiling, benchmarking, and analyzing code could take days or even weeks. Performance tuning is prohibitively expensive and non-trivial for most teams.”article, stated
“Previously, uncovering performance antipatterns demanded immense, specialized effort. For instance: * 5 critical antipatterns once required two engineers (including a Principal Engineer) for a full month (∼320 hours).”article, stated

Single-shot LLM detection

Rejected because: It produced inconsistent results, hallucinations, and non-runnable generated code.

“In our initial attempts, a single-shot LLM-based antipattern detection produced inconsistent and unreliable results—responses varied between runs, included hallucinations, and often generated non-runnable code.”article, stated
“In our initial attempts, a single-shot LLM-based antipattern detection produced inconsistent and unreliable results—responses varied between runs, included hallucinations, and often generated non-runnable code.”article, stated

Trust a single model's detection judgment

Rejected because: Uber added LLM juries and LLMCheck because a single model can hallucinate or misread code constructs.

“Rather than trusting a single model’s judgment, PerfInsights leverages a jury of large language models to validate each detected antipattern.”article, stated
“Even with LLM juries, LLM may still hallucinate, such as: * Detecting antipatterns that don’t exist * Confusing maps with slices and vice versa”article, stated

Patterns

eval-driven-development (evaluation)

PerfInsights uses LLMCheck metrics, dashboards, and validators to quantify detection accuracy, error patterns, and regressions.

“LLMCheck dashboards tracking detection accuracy, false positive reasons, and model regressions”article, stated

llm-as-judge (evaluation)

A jury of LLMs independently validates whether each detected antipattern and optimization recommendation is valid.

“PerfInsights leverages a jury of large language models to validate each detected antipattern.”article, stated

guardrails-io-filtering (safety)

LLMCheck applies domain-specific rule validators to catch false positives such as loop invariant or map/slice misinterpretations.

“LLMCheck by running through several domain-specific rule-based validators to evaluate LLM responses.”article, stated

prompt-versioning (prompt-operations)

Uber iteratively improved prompts with few-shot examples, audience/role framing, specific instructions, separate detection/validation prompts, and confidence scoring.

“We then introduced several targeted prompt strategies to enhance accuracy.”article, stated
“Use one prompt per antipattern to conserve context and break down complex tasks into simpler ones”article, stated

canary-rollout (operations)

The system earned adoption through early successful savings diffs before becoming part of the broader engineering toolkit.

“Landing the first 5 digits saving diff was a breakthrough moment.”article, stated

Tradeoffs

Use profiling before LLM analysis

Chose runtime profile-driven candidate selection over scanning all Go code with an LLM.

Rationale: Profiling focuses the expensive language-model step on functions that matter for real compute cost.

“uses runtime CPU and memory profiles with GenAI-powered static analysis to pinpoint expensive hotpath functions”article, stated
“ensuring ‌downstream analysis focuses only on service-owned code that’s most likely to benefit from optimization.”article, stated

Combine LLM juries with rule-based validation

Chose ensemble model judgment plus domain-specific validators over only one model or only static rules.

Rationale: The LLM can detect semantic antipatterns, while validators catch known false-positive classes and provide standardized metrics.

“two complementary systems: LLM juries and LLMCheck.”article, stated
“Standardized metrics: Tracks reductions in LLM response errors during prompt tuning.”article, stated

Embed optimization into continuous workflows

Chose CI/CD and day-to-day developer integration over reactive expert-led tuning only when systems hurt.

Rationale: Continuous surfacing makes performance tuning proactive and accessible to more teams.

“optimization opportunities are surfaced regularly, not just when something breaks.”article, stated

Gotchas (what bit them)

Early LLM outputs were noisy and inconsistent.

Root cause: Single-shot prompts lacked enough task framing, examples, and validation for code-antipattern detection.

Resolution: Add few-shot examples, Go-expert role framing, clear positive instructions, separate detection/validation prompts, and confidence scoring.

“Early iterations suffered from noisy, inconsistent outputs.”article, stated
“By encoding explicit antipattern definitions and Go-specific idioms into the prompts, we improved detection precision”article, stated

LLMs hallucinated antipatterns and code semantics.

Root cause: Models could detect nonexistent antipatterns, confuse maps with slices, or misidentify loop invariants.

Resolution: Use LLM juries plus LLMCheck domain-specific validators to catch false positives before developer action.

3 supporting quotes
“Detecting antipatterns that don’t exist”article, stated
“Confusing maps with slices and vice versa”article, stated
“PerfInsights employs a second layer of verification via LLMCheck”article, stated

Unfiltered code search space would overwhelm the detector and developers.

Root cause: A large monorepo contains dependencies, runtime internals, and low-value functions that are unlikely optimization targets.

Resolution: Filter aggressively to top expensive service-owned functions before GenAI analysis.

“PerfInsights applies a static filter that excludes open-source dependencies and internal runtime functions.”article, stated
“we constrained the search space.”article, stated

Evaluation

Uber evaluates PerfInsights through validated detection counts, LLMCheck false-positive metrics, hallucination-rate reduction, merged diffs, time-saved estimates, and codebase antipattern reduction over time.

Metrics: false positives reduced from over 80% to low teens · 33.5% reduction in validated detections over four months · 3,800 projected engineering hours saved annually · 93.10% time savings per issue · hundreds of merged diffs

3 supporting quotes
“reducing false positives from over 80% to the low teens.”article, stated
“a 33.5% reduction in just four months.”article, stated
“With hundreds of diffs already generated and merged into Uber’s Go monorepo”article, stated

Outcomes

The system targets Uber's Go monorepo and the high-cost services whose top 10 accounted for more than multi-million dollars of compute spend in March 2024.

3 supporting quotes
“With hundreds of diffs already generated and merged into Uber’s Go monorepo”article, stated
“Over four months, the number of antipatterns reduced from 265 to 176”article, stated
“PerfInsights has redefined performance tuning as a continuous, data-driven discipline.”article, stated