Papers
Topics
Authors
Recent
Search
2000 character limit reached

MOA: A Profiling-Guided LLM Framework for Memory-Optimization Automation at Codebase Scale

Published 30 Jun 2026 in cs.SE | (2606.31368v1)

Abstract: Modern large-scale software systems often suffer from pervasive memory inefficiencies (e.g., bloat, churn), leading to excessive resource costs and performance degradation. Existing optimization workflows lack end-to-end automation, forcing developers to manually synthesize complex tool outputs into actionable and semantics-preserving fixes, precluding scalability in large codebases. To address this, this paper presents MOA, an LLM-driven framework that automatically detects and repairs recurring memory inefficiencies across production-scale codebases. Specifically, MOA operates through three agents: an Analyzer that mines anti-patterns from profiling data, a Checker Generator that synthesizes static analyzers through template-guided refinement, and a Patcher that generates optimization patches via state-machine-driven workflows. Our evaluation on OpenHarmony, an open-source operating system with over 100 million lines of C/C++ code, shows that MOA identifies 13 anti-patterns (9 previously unknown) from 3 profiled services, detects over 10,000 inefficiencies across a broader set of 7 services, and generates 769 patches with 92.5% expert acceptance rate, achieving 42.2% heap reduction and 10.6% binary size reduction on average. We envision MOA as a valuable tool for performance engineering at production scale.

Summary

  • The paper introduces MOA, a fully automated framework that leverages LLMs and profiling data to detect and remediate memory inefficiencies in large-scale C/C++ codebases.
  • The approach integrates pattern mining, static checker synthesis, and state-driven patch generation, yielding a 42.2% heap reduction and 10.6% binary size decrease.
  • The framework outperforms existing tools with a 92.5% patch acceptance rate and discovers 69.3% undocumented anti-patterns, highlighting its scalability and efficacy.

Automated Memory Optimization at Codebase Scale: An Expert Essay on "MOA: A Profiling-Guided LLM Framework for Memory-Optimization Automation at Codebase Scale"

Introduction and Motivation

Memory inefficiencies—manifesting as bloat, allocation churn, and persistent heap waste—are pervasive in production-grade C/C++ codebases, yet notoriously challenging to eradicate at scale. Unlike functional bugs, these issues rarely produce immediate failures, instead silently degrading responsiveness, increasing resource consumption, and accumulating as latent technical debt. Traditional remediation strategies depend heavily on manual correlation between dynamic profiling traces and source code, a process incompatible with large, actively-evolving repositories. Static analysis tools like Clang-Tidy provide only partial coverage and demand manual formalization by experts.

"MOA: A Profiling-Guided LLM Framework for Memory-Optimization Automation at Codebase Scale" (2606.31368) introduces MOA, a fully automated framework that leverages LLMs and runtime profiling data to bridge the gap between empirical inefficiency evidence and codebase-wide, semantics-preserving optimization. MOA encompasses three tightly integrated stages: pattern mining, static checker synthesis, and automated patch generation, orchestrated by LLM-based agents, with demonstrated effectiveness on OpenHarmony—an open-source OS comprising over 100 million C/C++ LOC. Figure 1

Figure 1: Example of header-initialized static map anti-pattern leading to code and memory duplication across translation units.

The MOA Architecture and Workflow

MOA comprises three primary components, each realized as an LLM-driven agent:

Pattern Mining

The Analyzer agent ingests dynamic profiling data—heap traces, allocation timings, and stack traces—by importing them into a queryable relational database. Through structured relevance queries and context-driven exploration, the Analyzer identifies recurring anti-patterns associated with excessive memory consumption or redundant binary emissions. Reports are constructed using a four-part templated schema: empirical evidence, inefficiency rationale, static detection logic, and prescribed optimization strategy. Critically, a Reviewer agent performs independent report vetting, mitigating LLM self-reinforcing bias and improving actionability. Figure 2

Figure 2: MOA workflow—profiling evidence leads to anti-pattern mining, static checker synthesis, and finally, context-aware patch generation.

Checker Synthesis

Validated anti-pattern reports are transformed into actual static analyzers, instantiated (by default) atop the Clang Static Analyzer (CSA). The Checker Generator produces a compilable checker prototype by mapping the abstract detection logic into concrete code, conforming to CSA APIs and skeletal templates. Compilation and validation are performed iteratively: synthesized checkers are evaluated against both positive and negative code exemplars from the anti-pattern reports, driving further refinement until diagnostic completeness and precision is achieved.

Patch Generation

Detected inefficiency instances are grouped and contextualized for patching. The Patcher agent, implemented as a state machine, operates in a loop of context gathering, edit application, and syntax validation. The workflow ensures coordinated, semantics-preserving edits, particularly for cases requiring multi-location, cross-file refactoring. The process is driven by both anti-pattern-guided fix strategies and LSP-aided context acquisition, with robust checkpointing and recovery boundaries to maintain correctness during non-local transformations. Figure 3

Figure 3: State machine workflow for the Patcher—coordinating preparation, patching, and validation with explicit error recovery.

Empirical Evaluation on OpenHarmony

MOA is evaluated on the production-scale OpenHarmony operating system. Experiments utilize profiling data from three services to mine anti-patterns and extend checker-based detection and repair across four additional, unprofiled services.

Pattern Discovery and Novelty

From three profiled services, MOA mines 13 anti-patterns (65% yield rate from candidates), with only 30.7% overlapping with Clang-Tidy's performance checks; notably, 69.3% are previously undocumented and undetectable by rule-based static analysis. Dominant anti-patterns include:

  • Static Object Overuse: Non-trivial statics in headers, redundantly instantiated per TU, causing code and heap bloat.
  • Inefficient Temporary Strings: Construction/churn of temporaries.
  • Redundant Copy Paths: Superfluous pass-by-value and copy initialization.
  • Persistent Const Heap Structures: Immutable but unnecessarily heap-allocated objects.

Checker Efficacy and Generalization

Synthesized checkers (one per validated pattern) discover over 10,000 inefficiencies in 7 services comprising 971K LOC. Importantly, patterns identified via targeted profiling of a code subset generalize to services outside the original profiling scope, underscoring MOA's capacity to propagate memory fixes codebase-wide.

Automated Patch Generation and Optimization

MOA generates 769 file-level patches for 1,825 optimization targets in 518 files across 7 services. Human maintainers accept 92.5% of patches after review. Quantitative performance metrics report an average 42.2% reduction in heap consumption, 17% reduction in proportional set size, and 10.6% reduction in binary size. Figure 4

Figure 4: Example of anti-pattern report drafting and reviewing iteration between agents.

Comparison and Ablation

A head-to-head with PatchAgent—an autonomous, LLM-driven program repair agent—reveals that MOA achieves an 88.8% patch acceptance rate, versus PatchAgent's 10.3%. The superior performance is attributed to MOA's explicit pattern mining, context-aware detection, and state-driven patch validation.

Ablation studies show that static checker-based localization is critical: removing checkers leads to a 46% loss in patch accuracy. Removing anti-pattern guidance alone degrades performance modestly, highlighting the value of precise localization over conceptual guidance for scaling a codebase-wide optimization.

Theoretical and Practical Implications

MOA establishes several key advances. First, it validates that profiling-guided anti-pattern mining, coupled with LLM reasoning, can surface latent, project-specific memory optimization opportunities missed by both static heuristics and repository mining. Second, checker synthesis bridges dynamic symptom localization and static recurrence detection, enabling exhaustive, precise optimization at codebase scale. Finally, state-driven autonomous patch generation enables complex, semantics-preserving refactoring beyond the limitations of one-shot or functionally constrained LLM agents.

Practically, MOA's low per-patch cost (∼$0.50), high acceptance rate, and ease of extension to other optimization domains (subject to profiling and static toolchain porting) position it as a viable component in CI/CD performance engineering pipelines. The pipeline is modular: adapting to new languages or optimization dimensions (e.g., CPU/cache, I/O) principally requires new profilers and static analysis backends.

Future Directions

Prospective research avenues include:

  • Extension to Broader Performance Metrics: Generalizing the pattern mining and patching methodology to CPU, cache, and I/O inefficiencies using suitable dynamic profiling.
  • Support for Functional Refactoring: Integrating correctness-preserving transformations beyond non-functional “safe” optimizations, necessitating deeper semantic and regression validation.
  • Optimization-Maintainability Trade-offs: Dynamically balancing code readability, maintainability, and performance objectives, potentially via multi-objective optimization during pattern abstraction and patch synthesis.

Conclusion

MOA leverages profiling-guided anti-pattern discovery, LLM-driven static checker synthesis, and autonomous agentic patch generation to provide an end-to-end, semantics-preserving approach to codebase-scale memory optimization. Its empirical success on OpenHarmony demonstrates substantial resource and binary size reductions, high patch accuracy, and the ability to discover previously undocumented inefficiencies. The framework represents a substantive step toward fully autonomous, production-grade performance engineering.

Paper to Video (Beta)

No one has generated a video about this paper yet.

Whiteboard

No one has generated a whiteboard explanation for this paper yet.

Open Problems

We haven't generated a list of open problems mentioned in this paper yet.

Collections

Sign up for free to add this paper to one or more collections.

Tweets

Sign up for free to view the 1 tweet with 6 likes about this paper.