NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Fast and Memory-Efficient Neural Code Completion

Alexey Svyatkovskiy, Sebastian Lee, Anna Hadjitofi, Maik Riechert, Juliana Vicente Franco, Miltiadis Allamanis

TL;DR

This paper introduces a modular framework that shifts neural code completion from a "generation" task to a "reranking" task. By leveraging existing static analysis to provide candidates and using granular token encodings, the authors produced a model that consumes only 6 MB of RAM (a 19x reduction over baselines) and delivers suggestions in 8 ms with 90% top-5 accuracy.

What Problem Does This Paper Address?

Modern Integrated Development Environments (IDEs) like Visual Studio or IntelliJ rely heavily on code completion. While deep learning has significantly improved the accuracy of these suggestions, state-of-the-art models are often "bloated." They frequently require hundreds of megabytes of RAM and significant CPU power, which is a dealbreaker for developers on resource-constrained machines or those who want a snappy, lightweight editor experience.

Furthermore, most neural models treat code completion as a language modeling problem—trying to predict the next token from scratch. This ignores the "free" information already available in IDEs via static analysis (like type checking), which can already narrow down the list of valid possibilities.

Methods

The authors propose a modular framework consisting of four parts:

  1. Token Encoder: Converts code tokens into vectors. They explored several types, including Subtoken and Byte-Pair Encoding (BPE), which break down long variable names (like array_inner_product) into smaller, more manageable pieces.
  2. Context Encoder: Summarizes the surrounding code. They tested RNNs (GRUs), CNNs, and Transformers.
  3. Candidate Provider: Instead of generating text, this module provides a list of potential completions. The "standard" way is a fixed vocabulary, but the authors' novel approach uses Static Analysis (StAn) to provide a dynamic list of type-correct candidates.
  4. Completion Ranker: A neural component that takes the context and the candidates, then ranks them using a dot-product similarity (the "DOT" ranker).

By combining these, they move from generation (predicting 1 out of 50,000 words) to reranking (sorting 10–50 valid candidates provided by the IDE).

Datasets

The researchers used a dataset of 2,700 top-starred Python repositories from GitHub.

  • Deduplication: They carefully deduplicated the code to prevent "memorization" from skewing results.
  • Scale: The final dataset contained 255k files and 7.4 million API completion instances.
  • Evaluation: They specifically held out three libraries (jax, horovod, pyspark) to test how well the models generalize to APIs they never saw during training.

Key Insights and Ideas

  • Ranking is Easier than Generation: By letting static analysis do the "heavy lifting" of finding valid candidates, the neural model only needs to learn the intent of the developer, which requires a much smaller footprint.
  • Granular Encodings Matter: Using subtokens or BPE allows the model to understand the meaning of a variable name it has never seen before by looking at its components (e.g., recognizing inner and product).
  • Context Annotation: The authors found that "pointing" the model to specific tokens—like marking every occurrence of the variable currently being acted upon—provided a small but consistent boost in accuracy at almost no computational cost.
  • The Pareto Front: The paper emphasizes that there isn't one "best" model, but rather a "Pareto front" where developers can choose to sacrifice a tiny bit of accuracy for massive gains in speed or memory efficiency.

Key Results

  • Efficiency: Their best-performing small model uses just 6 MB of RAM, compared to the ~115 MB+ required by previous state-of-the-art BPE models.
  • Latency: The model computes a suggestion in roughly 8 ms on a CPU, well within the "tens of milliseconds" budget required for a fluid typing experience.
  • Accuracy: Despite the small size, the model achieves 90% Recall@5 (the correct answer is in the top 5 suggestions 90% of the time).
  • Generalization: In tests on unseen libraries, the BPE-based reranking model significantly outperformed standard vocabulary-based models, proving it can handle "zero-day" APIs.

Limitations and Future Work

  • Static Analysis Dependency: The "StAn" models rely on the IDE's ability to perform static analysis. If the code is in a highly broken state where static analysis fails, the model's performance may degrade or revert to a simpler mode.
  • Training without a Static Analyzer: The authors briefly explored training using "random distractors" as a proxy for static analysis candidates, but found it led to some performance loss. Improving training for environments where static analysis is unavailable remains an open challenge.
  • Deployment: These models are not just theoretical; the authors note they have been integrated into Microsoft’s Visual Studio IntelliCode, serving real-world developers.

Summary updated

BibTeX
@inproceedings{svyatkovskiy2021fast,
  author = {Alexey Svyatkovskiy and Sebastian Lee and Anna Hadjitofi and Maik Riechert and Juliana Vicente Franco and Miltiadis Allamanis},
  title = {{Fast and Memory-Efficient Neural Code Completion}},
  booktitle = {MSR},
  year = {2021},
  url = {https://openreview.net/forum?id=w135opif9O},
}

Loading related content...

Figure