A Transformer-Based Approach for Smart Invocation of Automatic Code Completion

Aral de Moor, Arie van Deursen, Maliheh Izadi

TL;DR

This paper introduces JONBERTA, a lightweight transformer model that intelligently predicts when to trigger code completion suggestions. By combining code context with user telemetry, JONBERTA significantly reduces intrusive and unnecessary suggestions, improving developer experience and efficiency without sacrificing performance.

What Problem Does This Paper Address?

Modern AI-powered code completion tools, like GitHub Copilot, are incredibly powerful but can also be a double-edged sword. While they excel at generating code, they often suffer from high operational costs and can be disruptive. Developers can be interrupted by too many suggestions, or suggestions that aren't relevant to their current task. Existing research has largely focused on improving the quality of suggestions, but this paper tackles a crucial aspect of the user experience: determining the right time to offer a suggestion. The authors argue that simply optimizing for suggestion acceptance rate isn't enough; we need to understand when a developer wants a suggestion, whether they accept it or not, and when they might prefer no suggestion at all.

Methods

The core of this work is a novel machine learning model called JONBERTA (Jointly Optimised Attention). JONBERTA is a transformer-based model designed to predict whether a code completion suggestion should be invoked. It achieves this by integrating two key types of information:

  • Code Context: This includes the code before (prefix) and after (suffix) the cursor. The authors propose a unique "centered-on-cursor" tokenization strategy to ensure the most relevant parts of the code are prioritized.
  • Telemetry Data: This encompasses various user interaction signals from the Integrated Development Environment (IDE), such as time since the last completion, document length, and cursor position.

JONBERTA comes in two main flavors: JONBERTA-HEAD, which incorporates telemetry into the classification head, and JONBERTA-ATTN, which integrates telemetry features directly into the self-attention mechanism. Both are designed to be parameter-efficient, adding minimal overhead.

Datasets

The researchers collected a dataset of approximately 200,000 developer interactions with their custom code completion plugin, CODE4ME. This dataset was used to train and evaluate their models. For testing, they used a separate set of around 20,000 interactions. They also discuss the importance of dataset balancing, finding that a "biased" distribution, which gives roughly equal weight to different invocation types (manual, automatic accepted, automatic rejected), leads to better performance.

Key Insights and Ideas

  • Timing is Everything: The paper strongly emphasizes that the when of code completion is as important as the what. Intrusive suggestions can be more detrimental than helpful.
  • Beyond Acceptance Rate: Simply aiming for a high acceptance rate for suggestions is a flawed metric. The authors propose a more nuanced approach that considers manual invocations (even if rejected) as positive signals, indicating developer intent.
  • Telemetry is Gold: User interaction data from the IDE is a rich source of information that can significantly improve the prediction of when a developer needs assistance.
  • Transformer Power for Filtering: The authors demonstrate that transformers, typically used for generation, are also highly effective for "smart filtering" tasks, outperforming simpler baselines.
  • Parameter Efficiency Matters: For real-time applications like code completion, lightweight models are crucial. JONBERTA achieves strong results with minimal additional parameters.

Key Results

  • Offline Performance: JONBERTA models significantly outperformed baseline logistic regression and even a CODEBERTA model trained solely on code context, achieving an average accuracy of around 82%.
  • Online Evaluation: In a real-world deployment with 34 developers over two weeks (74,000 requests), JONBERTA-HEAD achieved the best performance based on a harmonic mean of acceptance rate and code quality (measured by CodeBERTScore).
  • Latency: The JONBERTA models maintained low latency, crucial for seamless integration into the development workflow. The filtering process adds minimal overhead compared to the code completion model itself.

Limitations and Future Work

The authors acknowledge several limitations:

  • Dataset Size: The training dataset, while substantial, could be larger to fully explore the potential of hybrid transformer models.
  • Generalizability: The findings are based on a specific code completion plugin (CODE4ME) and might not directly transfer to all other tools due to differences in features and invocation mechanisms.
  • Proxy Metrics: The harmonic mean of acceptance rate and CodeBERTScore is a proxy for usability and quality. Future work could involve qualitative studies (e.g., developer interviews) for a deeper understanding.

Future work could involve exploring larger datasets, investigating personalization techniques for invocation filtering, and understanding the long-term impact of AI-assisted coding on software development. The ethical considerations of data usage and privacy are also highlighted, with the authors ensuring user consent and anonymization where possible.

Summary updated

BibTeX
@inproceedings{moor2024transformer,
  author = {Aral de Moor and Arie van Deursen and Maliheh Izadi},
  title = {{A Transformer-Based Approach for Smart Invocation of Automatic Code Completion}},
  booktitle = {AIWare},
  year = {2024},
  url = {https://openreview.net/forum?id=KOiKmQmIlS},
}
Figure