Introduction
Programming-by-Example (PBE) has revolutionized end-user automation, enabling non-programmers to perform complex data transformations by simply providing input-output examples. Tools like Microsoft Excel's FlashFill have demonstrated the power of this paradigm in tasks such as date reformatting and string manipulation. However, while traditional PBE focuses on finding any program that satisfies the provided examples, it often neglects the quality of the generated code.
The Quality Gap in PBE
The primary objective of standard PBE systems is intent disambiguation—guessing what the user wants from a minimal set of examples. This often leads to "spaghetti code" within a restricted Domain-Specific Language (DSL). Such code is frequently inefficient, making it unsuitable for large-scale data processing, and unreadable, making it difficult for software engineers to maintain or verify. For PBE to be production-ready, it must optimize for quantitative metrics like execution speed and code conciseness.
The qPBE Framework
To address these challenges, the authors propose qPBE, a three-phase framework designed to synthesize high-quality, performant code. The framework decouples the task of understanding user intent from the task of optimizing the program's structure and performance.
1. Intent Disambiguation
The process begins with a standard PBE solver generating an initial "draft" program from the user's few examples. This draft is then used to process a larger set of unlabeled inputs, creating a robust set of synthetic examples. This step "locks in" the intended behavior before optimization begins, ensuring that subsequent transformations do not alter the program's logic.
2. Global Search
With the synthetic examples in hand, the system re-invokes the PBE solver using a cost-based ranking function. Instead of searching for the most probable program, it explores the entire program space to find the "cheapest" one—typically defined by the fewest number of operations or the most efficient logic structure.
3. Local Search
The final phase employs rewrite rules to bridge the gap between the internal DSL and the target production language (e.g., Python). This phase replaces generic PBE operators with high-performance native library calls, such as Python’s datetime module. This "upgrades" the logic into professional-grade code that is both faster and more readable.
Evaluation and Results
The qPBE framework was evaluated against 701 benchmarks involving text transformation tasks from academic and industrial sources. The results demonstrate significant improvements over the FlashFill baseline:
- Execution Speed: Optimized programs were, on average, 2.7x faster. In specific cases involving complex regular expressions, replacing them with native string operations resulted in speedups of up to 3400x.
- Code Compactness: The framework produced programs that were 1.53x smaller on average, significantly enhancing readability.
- Efficiency: The optimization process is highly efficient, adding only approximately 1.23 seconds of overhead, maintaining the interactivity expected of PBE tools.
Conclusion
The qPBE framework represents a significant step toward making synthesized code production-ready. By separating intent disambiguation from performance optimization and leveraging native language features through local search, qPBE produces code that meets the rigorous standards of data scientists and software engineers. Future work includes automating the discovery of rewrite rules and expanding optimization targets to include memory usage and security.
Summary updated