Tuning LLM-based Code Optimization via Meta-Prompting: An Industrial Perspective

Jingzhi Gong, Rafail Giavrimis, Paul Brookes, Vardan Voskanyan, Fan Wu, Mari Ashiga, Matthew Truscott, Mike Basios, Leslie Kanthan, Jie Xu, Zheng WangarXiv 2025 · DOI

Abstract

Industrial code optimization platforms increasingly leverage Large Language Models (LLMs) to identify performance bottlenecks. However, the "cross-model bottleneck"—where prompts optimized for one model fail on another—presents a significant scaling challenge. This paper introduces Meta-Prompted Code Optimization (MPCO), a framework that utilizes a high-end LLM to dynamically synthesize specialized prompts for target models. By integrating project metadata and model-specific context, MPCO achieves up to a 19% performance boost across real-world codebases with minimal human intervention.

The Challenge of Industrial Code Optimization

In performance-critical domains such as high-frequency trading and scientific computing, micro-optimizations are essential. Industrial platforms like TurinTech AI’s ARTEMIS utilize LLMs to discover optimizations that often elude human engineers.

A primary obstacle in this workflow is the cross-model prompt engineering challenge. A prompt tailored for GPT-4o may lead to hallucinations or suboptimal code when applied to Claude or Gemini. Manually maintaining unique prompts for every combination of LLM, language, and project is unscalable. Existing techniques like Chain-of-Thought or Few-Shot prompting are often too generic or computationally expensive for production environments handling thousands of daily requests.

Methods: The MPCO Framework

MPCO (Meta-Prompted Code Optimization) replaces static prompting with a dynamic "Meta-Prompter" system. This high-end LLM acts as a personalized tutor, synthesizing bespoke prompts for a "Target LLM" based on specific environmental context.

The MPCO architecture within the Artemis Platform, showing the integration of profiling, context collection, and meta-prompting.

The workflow consists of four automated stages:

  1. Profiling: Industry-standard tools (e.g., Intel VTune) identify the top "hot" code snippets responsible for performance lags.
  2. Context Collection & Meta-Prompting: MPCO gathers Project Context (metadata/languages), Task Context (optimization goals), and LLM Context (target model strengths). The Meta-Prompter uses this data to generate a specialized prompt.
  3. Multi-LLM Optimization: Target LLMs receive these bespoke prompts to produce optimized code variants.
  4. Validation: The system automatically compiles the code, runs unit tests, and benchmarks runtime to verify speedups.

Experimental Setup

The framework was evaluated across five diverse, performance-critical open-source projects: BitmapPlusPlus (C++), Llama.cpp (C++), RPCS3 (C++), Faster-Whisper (Python), and Langflow (Python). Evaluation involved 366 hours of runtime benchmarking to ensure statistical significance.

Key Results and Insights

MPCO demonstrated superior performance, achieving the best statistical rank across all tested systems. It delivered a mean runtime improvement of up to 19.06% on the BitmapPlusPlus project.

Comparison of MPCO against other prompting strategies across industrial requirements, highlighting its adaptability and low overhead.

Key findings include:

  • Contextual Importance: Ablation studies revealed that Project Context is the most critical factor; its removal caused the most significant performance degradation.
  • Industrial Efficiency: Generating a meta-prompt costs approximately $0.003 and takes under 4 seconds, offering a massive scalability advantage over manual engineering.
  • Quality of Edits: 96% of top optimizations were meaningful algorithmic or memory management improvements rather than trivial formatting changes.

Limitations and Future Work

Currently, MPCO is limited to function-level optimizations and does not yet address system-wide changes across multiple files. Furthermore, the validation process relies heavily on the quality of existing project unit tests. Future research will explore "Agentic" meta-prompting, where multiple AI agents iteratively refine prompts through collaborative feedback loops to further enhance optimization depth.

Summary updated

BibTeX
@misc{gong2025tuning,
  author = {Jingzhi Gong and Rafail Giavrimis and Paul Brookes and Vardan Voskanyan and Fan Wu and Mari Ashiga and Matthew Truscott and Mike Basios and Leslie Kanthan and Jie Xu and Zheng Wang},
  title = {{Tuning LLM-based Code Optimization via Meta-Prompting: An Industrial Perspective}},
  year = {2025},
  eprint = {2508.01443},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2508.01443},
}
Figure