Toward Less Hidden Cost of Code Completion with Acceptance and Ranking Models

Jingxuan Li, Rui Huang, Wei Li, Kai Yao, Weiguo Tan

TL;DR

This paper tackles the problem of "hidden costs" in code completion, where frequent but often incorrect suggestions degrade developer experience. They introduce an "acceptance model" to filter out bad suggestions and a "fusion ranking model" to intelligently reorder the remaining ones. This combined approach significantly improves accuracy and introduces a new "Benefit-Cost Ratio" metric that better reflects real-world usability.

What Problem Does This Paper Address?

Code completion tools are ubiquitous in modern IDEs, aiming to boost developer productivity by suggesting code snippets. While advancements have enabled longer and more flexible completions, this has led to an increase in irrelevant or incorrect suggestions (false positives). This deluge of bad suggestions forces developers to sift through them, increasing cognitive load and negating the intended productivity gains. Furthermore, existing evaluation metrics often fail to capture this "hidden cost" of browsing and evaluating these suggestions, making it difficult to compare different approaches effectively. The paper aims to address these issues by developing a system that not only improves the accuracy of suggestions but also quantifies and optimizes for the user experience.

Methods

The core of this work lies in two novel models:

  • Acceptance Model: This model acts as a gatekeeper. It takes features from the code context and the suggestions provided by various underlying completion models. Using these features, it predicts the probability that a correct suggestion exists within the entire set of candidates. If this probability is low, the model rejects the entire completion list, preventing developers from seeing potentially useless suggestions. This is framed as a binary classification problem.
  • Fusion Ranking Model: For the completion lists that pass the acceptance model, this component reorders the candidates. It's designed to be flexible, handling suggestions of varying types and lengths from different models. The model learns to assign a priority score to each candidate, aiming to place the most beneficial (considering both accuracy and length) suggestions at the top. This is also framed as a regression problem to predict an "expected benefit."

Additionally, the authors propose a new evaluation metric called Benefit-Cost Ratio (BCR). This metric quantifies the net benefit by considering the keystrokes saved (benefit) minus the cost of browsing the completion list (hidden cost).

Datasets

The authors utilize a dataset derived from the Java-small dataset by Alon et al. [30], which is a subset of Allamanis et al. [31]. This dataset consists of approximately 96.5k Java source files from popular GitHub projects. They apply several filtering steps, including removing test files, specific methods (like toString, equals), and overly long methods, to create their training, simulation, and test sets. The simulation dataset is crucial for collecting data on various completion strategies and training the acceptance and fusion ranking models.

Key Insights and Ideas

  • The "Hidden Cost" is Real and Quantifiable: The paper convincingly argues that the time and effort spent sifting through incorrect code suggestions is a significant, often overlooked, cost. Their BCR metric provides a way to measure this, moving beyond simple accuracy.
  • Filtering is as Important as Suggesting: The acceptance model's ability to block entire lists of bad suggestions is a key innovation. It dramatically reduces the noise and improves the perceived quality of the completion system.
  • Length Matters for Benefit: The fusion ranking model's insight that longer correct suggestions are generally more beneficial (as they save more typing) is crucial. This moves beyond simply ranking by probability.
  • Ensembling Pays Off: Combining multiple diverse strategies (frequency-based and neural) with intelligent filtering and ranking yields better results than any single strategy alone.

Key Results

The proposed acceptance and fusion ranking models, when integrated with two frequency-based models and a GPT-2 language model, demonstrate significant improvements:

  • False Positive Reduction: The percentage of false-positive completion lists is reduced from 55.09% to 17.44%.
  • Accuracy Improvement: TOP1 accuracy increases by 27.80%, and TOP5 accuracy increases by 37.64%.
  • Benefit-Cost Ratio (BCR): The integrated system achieves a BCR of 3.65, indicating that, on average, a developer saves 3.65 keystrokes per completion by using this system. This is a substantial improvement over individual strategies.

Limitations and Future Work

The authors acknowledge that their work focuses on a specific set of completion strategies and that integrating more diverse strategies could yield further benefits. They also suggest exploring multi-task joint training or reinforcement learning for optimizing the ensemble model. In terms of evaluation, they express interest in discovering more potential influencing factors and combinations for even more robust evaluation methods. The current simulation-based approach, while effective, is an offline method, and real-world user studies would be valuable for further validation.

Summary updated

Abstract

Code completion is widely used by software developers to provide coding suggestions given a partially written code snippet. Apart from the traditional code completion methods, which only support single token completion at minimal positions, recent studies show the ability to provide longer code completion at more flexible positions. However, such frequently triggered and longer completion results reduce the overall precision as they generate more invalid results. Moreover, different studies are mostly incompatible with each other. Thus, it is vital to develop an ensemble framework that can combine results from multiple models to draw merits and offset defects of each model. This paper conducts a coding simulation to collect data from code context and different code completion models and then apply the data in two tasks. First, we introduce an acceptance model which can dynamically control whether to display completion results to the developer. It uses simulation features to predict whether correct results exist in the output of these models. Our best model reduces the percentage of false-positive completion from 55.09% to 17.44%. Second, we design a fusion ranking scheme that can automatically identify the priority of the completion results and reorder the candidates from multiple code completion models. This scheme is flexible in dealing with various models, regardless of the type or the length of their completion results. We integrate this ranking scheme with two frequency models and a GPT-2 styled language model, along with the acceptance model to yield 27.80% and 37.64% increase in TOP1 and TOP5 accuracy, respectively. In addition, we propose a new code completion evaluation metric, Benefit-Cost Ratio(BCR), taking into account the benefit of keystrokes saving and hidden cost of completion list browsing, which is closer to real coder experience scenario.
BibTeX
@misc{li2021toward,
  author = {Jingxuan Li and Rui Huang and Wei Li and Kai Yao and Weiguo Tan},
  title = {{Toward Less Hidden Cost of Code Completion with Acceptance and Ranking Models}},
  year = {2021},
  eprint = {2106.13928},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2106.13928},
}
Figure