Supersonic: Learning to Generate Source Code Optimizations in C/C++
Zimin Chen, Sen Fang, Martin Monperrus
TL;DR
Supersonic addresses automated source-code optimization at the source level by learning targeted edits from pairs of related programs. It leverages a seq2seq model initialized with CodeBERT to predict diff-based patches, using a three-phase inference pipeline: canonicalization, diff synthesis, and post-processing, and is trained on a large, carefully filtered Codeforces/AIZU/AtCoder dataset with CodeNet-derived pretraining. Compared to OpenAI's GPT-3.5-Turbo and GPT-4 on competitive programming tasks, Supersonic delivers superior optimization performance while being ~600x–3700x smaller, and the diff-based output representation further boosts effectiveness, albeit with some malformed patch rejections that reduce accessible predictions. The work demonstrates the value of compact, patch-like code edits and meticulous data curation for reliable code optimization, with external validity demonstrated via submission to real contest platforms. Overall, Supersonic combines a focused patch-based generation objective with domain-specific pretraining to achieve efficient, scalable source-code optimizations that generalize beyond synthetic benchmarks.
Abstract
Software optimization refines programs for resource efficiency while preserving functionality. Traditionally, it is a process done by developers and compilers. This paper introduces a third option, automated optimization at the source code level. We present Supersonic, a neural approach targeting minor source code modifications for optimization. Using a seq2seq model, Supersonic is trained on C/C++ program pairs ($x_{t}$, $x_{t+1}$), where $x_{t+1}$ is an optimized version of $x_{t}$, and outputs a diff. Supersonic's performance is benchmarked against OpenAI's GPT-3.5-Turbo and GPT-4 on competitive programming tasks. The experiments show that Supersonic not only outperforms both models on the code optimization task but also minimizes the extent of the change with a model more than 600x smaller than GPT-3.5-Turbo and 3700x smaller than GPT-4.
