Introduction
In software engineering, Donald Knuth’s adage that "premature optimization is the root of all evil" is often taken as a mandate to ignore performance during initial development. While this helps manage complexity, it frequently leads to the neglect of the "critical 3%"—the hot paths where data structure choices and parameter tuning can significantly impact system efficiency. Developers typically rely on default implementations, such as Java's ArrayList or HashMap, and rarely adjust initialization parameters like capacity.
These seemingly minor decisions accumulate into substantial execution overhead, CPU cycles, and memory bloat. However, manually exploring the vast search space of alternative data structures and their configurations is a laborious and error-prone task. To address this, we present Artemis, an automated, cloud-based framework that treats data structures as competing organisms in an evolutionary race to optimize software performance.
The Artemis Framework
Artemis is a multi-objective search-based optimization framework designed to automate the selection and tuning of data structures. It operates as a source-to-source transformer, producing human-readable "diffs" that can be easily integrated into existing codebases. The framework operates in three distinct stages:
- Discovery (The Extractor): Artemis parses the program’s Abstract Syntax Tree (AST) to identify "Darwinian Data Structures" (DDS). These are implementations that share a common Abstract Data Type (ADT) interface—such as
ListorSet—making them functionally interchangeable. - Search (The Optimizer): Using the NSGA-II genetic algorithm, Artemis explores the search space by treating data structure choices and construction parameters (e.g., initial capacity) as "genes." This allows the system to evolve variants of the program that balance different performance goals.
- Evaluation (The Profiler): Each variant is executed against the project's existing test suite. Artemis measures three primary objectives: execution time, memory consumption, and CPU usage.
A key technical contribution of Artemis is its ability to handle the "program to interface" hurdle. Many developers declare variables using concrete classes (e.g., ArrayList) rather than interfaces (List). Artemis automatically applies "supertype" transformations to generalize these declarations, significantly expanding the available search space for optimization.
Experimental Evaluation
The effectiveness of Artemis was evaluated across a diverse corpus of 43 Java projects, including high-profile GitHub libraries (e.g., google-http-java-client), the standard DaCapo benchmark suite (e.g., xalan, pmd), and 30 randomly sampled GitHub projects to represent "average" code quality. To demonstrate language agnosticism, a case study was also conducted on Google’s Guetzli JPEG encoder, written in C++.
Key Results
Artemis successfully identified at least one optimized solution that improved all three performance metrics (time, memory, and CPU) for 86% (37 out of 43) of the tested projects. The median improvements across the best-found solutions were 4.8% for runtime, 10.1% for memory, and 5.1% for CPU usage.
Specific "big wins" highlight the potential of automated tuning:
google-http-java-client: Achieved a dramatic 46% reduction in execution time and a 39.6% reduction in CPU usage.xalan: Reduced memory consumption by 23.5%.- Cost-Effectiveness: The average cost to run Artemis in a cloud environment (Azure) was approximately £1.25 per project, demonstrating that automated optimization is significantly more economical than manual engineering effort.
Insights and Future Work
The success of Artemis stems from the realization that data structures are ideal targets for genetic algorithms due to their well-defined interfaces and diverse performance trade-offs. Furthermore, the results emphasize that tuning initial capacities is as vital as selecting the structure itself; proper sizing prevents both memory bloat and the overhead of frequent reallocations.
Because performance objectives are often in conflict (e.g., trading memory for speed), Artemis provides a set of "Pareto optimal" solutions. This allows developers to choose the configuration that best fits their specific deployment constraints.
Limitations
Despite its success, Artemis is dependent on the quality of the project's test suite. If tests do not cover performance-critical paths or fail to reflect real-world workloads, the resulting optimizations may not translate to production benefits. Additionally, while the current study focused on steady-state performance, future iterations could target startup time for short-lived applications. Finally, refining the search to focus on "hot" code paths identified by profiling could further accelerate the optimization process for massive projects.
Summary updated