RuleFlow : Generating Reusable Program Optimizations with LLMs

TL;DR

RuleFlow employs a three-stage pipeline to convert LLM-discovered code optimizations into reusable rewrite rules, achieving up to 4.3× speedup on Pandas benchmarks.

cs.SE 🔴 Advanced 2026-02-07 33 views
Avaljot Singh Dushyant Bharadwaj Stefanos Baziotis Kaushik Varadharajan Charith Mendis
program optimization large language models compiler techniques data analysis automation

Key Findings

Methodology

RuleFlow integrates offline LLM-driven optimization discovery with a rule-based deployment system. The process begins with the SNIPPETGEN module, which uses GPT-4 to generate candidate code rewrites from real-world Pandas snippets, followed by automated correctness and performance testing. Next, RULEGEN abstracts these rewrites into generalizable rules using multi-agent mechanisms that identify variable generalization, AST typing, and precondition synthesis, all encoded in a domain-specific language (DSL). Finally, CODEGEN applies these rules efficiently through static pattern matching, eliminating the need for further LLM calls during deployment. This hybrid approach leverages the flexibility of LLMs and the reliability of compiler techniques, enabling scalable, high-yield optimization.

Key Results

  • On PandasBench, RuleFlow achieved a maximum speedup of 4.3×, with an average of 1.54× over DIAS and 112.79× over MODIN, across 102 real Kaggle notebooks. The system generated 120 rewrite rules, with 88 validated for correctness, many applying to multiple notebooks with hit rates up to 87.13%. Individual rules reached up to 1704× acceleration, demonstrating high reusability and broad applicability.
  • The experimental results confirm that converting LLM-discovered optimizations into general rules significantly improves scalability and robustness, outperforming existing approaches in both speedup and rule coverage.
  • The framework’s ability to produce high-quality, reusable rules suggests a promising path for integrating AI-driven discovery with traditional compiler optimization, reducing reliance on costly LLM calls and enabling continuous improvement.

Significance

This work advances the field of program optimization by effectively combining LLMs’ creative potential with the deterministic reliability of compiler techniques. It addresses long-standing challenges of low yield and poor generalization in AI-assisted optimization, providing a scalable, automated solution for data analysis workloads. The methodology paves the way for broader application of AI in software engineering, promising more efficient, maintainable, and adaptable systems. Its impact extends beyond Pandas, offering a generalizable framework for optimizing diverse programming environments and domains.

Technical Contribution

The core innovation lies in the hybrid architecture that separates high-variance optimization discovery from deterministic rule application. The development of a multi-agent rule abstraction pipeline, with formalized preconditions in a DSL, ensures rules are both general and safe. The integration of GPT-4 for candidate generation, combined with static pattern matching for deployment, creates a scalable, end-to-end system that surpasses prior state-of-the-art methods like DIAS and MODIN. The approach also introduces a feedback loop for continuous rule refinement, enhancing robustness.

Novelty

This is the first comprehensive framework that systematically transforms LLM-generated code improvements into reusable, generalizable rules suitable for compiler deployment. Unlike previous work that relied solely on per-program optimization or static rewriting, RuleFlow’s three-stage pipeline ensures high-yield, scalable performance gains. Its innovative use of multi-agent abstraction and formalized rule representation distinguishes it from existing static or dynamic optimization techniques, opening a new avenue for AI-assisted compiler design.

Limitations

  • The generalization of rules depends on the diversity of initial optimizations; some complex or context-specific patterns may not be captured effectively, limiting applicability.
  • LLM-based candidate generation may produce semantically incorrect or suboptimal rewrites, requiring extensive validation and feedback cycles.
  • The current system focuses on Python/Pandas; extending to other languages or frameworks will require additional adaptation of the DSL and rule extraction processes.

Future Work

Future efforts will focus on enhancing rule generalization through multi-modal analysis, integrating dynamic runtime feedback, and expanding the DSL to support more complex semantic constraints. Additionally, exploring cross-language applicability and real-time adaptive optimization will broaden the framework’s utility, pushing the boundaries of AI-driven program synthesis and compilation.

AI Executive Summary

Data analysis workflows heavily rely on Pandas, a popular Python library, yet its performance bottlenecks hinder large-scale data processing. Traditional solutions like MODIN and DASK improve some aspects but often introduce overhead and limited optimization scope. Static compiler-based methods such as DIAS offer reliability but rely on manually engineered rules, which are insufficient for diverse real-world code patterns. Meanwhile, recent advances in large language models (LLMs) like GPT-4 have demonstrated remarkable capabilities in code understanding and generation, inspiring new approaches to program optimization. However, directly applying LLMs during runtime is costly and unreliable, with low success rates.

This paper introduces RuleFlow, a hybrid framework that bridges the gap by separating optimization discovery from deployment. In the offline phase, GPT-4 explores numerous code snippets, generating candidate rewrites that are automatically validated for correctness and performance gains. These are then abstracted into generalizable rewrite rules using a multi-agent system that captures variable generalization, AST typing, and applicability constraints, all encoded in a domain-specific language (DSL). During deployment, a lightweight pattern matcher applies these rules efficiently, enabling scalable, reliable performance improvements without further LLM calls.

Extensive experiments on PandasBench, a benchmark of real Kaggle notebooks, demonstrate RuleFlow’s superiority. It achieves up to 4.3× speedup, outperforms prior SOTA methods like DIAS by a factor of 2.8×, and vastly exceeds systems-based approaches such as MODIN, which can reach over 1700× acceleration on some rules. The high rule hit rate and broad applicability highlight the effectiveness of reusing optimized patterns across diverse codebases. This work not only advances the state-of-the-art in data analysis optimization but also establishes a scalable, generalizable paradigm for AI-assisted compiler design. Future directions include enhancing rule generalization, extending to other languages, and integrating dynamic feedback for adaptive optimization, promising a new era of intelligent, automated software engineering.

Deep Dive

Abstract

Optimizing Pandas programs is a challenging problem. Existing systems and compiler-based approaches offer reliability but are either heavyweight or support only a limited set of optimizations. Conversely, using LLMs in a per-program optimization methodology can synthesize nontrivial optimizations, but is unreliable, expensive, and offers a low yield. In this work, we introduce a hybrid approach that works in a 3-stage manner that decouples discovery from deployment and connects them via a novel bridge. First, it discovers per-program optimizations (discovery). Second, they are converted into generalised rewrite rules (bridge). Finally, these rules are incorporated into a compiler that can automatically apply them wherever applicable, eliminating repeated reliance on LLMs (deployment). We demonstrate that RuleFlow is the new state-of-the-art (SOTA) Pandas optimization framework on PandasBench, a challenging Pandas benchmark consisting of Python notebooks. Across these notebooks, we achieve a speedup of up to 4.3x over Dias, the previous compiler-based SOTA, and 1914.9x over Modin, the previous systems-based SOTA. Our code is available at https://github.com/ADAPT-uiuc/RuleFlow.

cs.SE cs.AI