[Paper Review] Context Composing for Full Line Code Completion
This paper presents a context-composing technique for full-line code completion using a compact, on-device Transformer model with under 1 billion parameters. By optimizing context composition through tokenization, scope-aware special tokens, and strategic code rearrangement, the approach achieves efficient, low-latency code suggestions that improve developer productivity without compromising privacy.
Code Completion is one of the most used Integrated Development Environment (IDE) features, which affects the everyday life of a software developer. Modern code completion approaches moved from the composition of several static analysis-based contributors to pipelines that involve neural networks. This change allows the proposal of longer code suggestions while maintaining the relatively short time spent on generation itself. At JetBrains, we put a lot of effort into perfecting the code completion workflow so it can be both helpful and non-distracting for a programmer. We managed to ship the Full Line Code Completion feature to PyCharm Pro IDE and proved its usefulness in A/B testing on hundreds of real Python users. The paper describes our approach to context composing for the Transformer model that is a core of the feature's implementation. In addition to that, we share our next steps to improve the feature and emphasize the importance of several research aspects in the area.
Motivation & Objective
- To develop an efficient, on-device code completion system that operates within strict latency and memory constraints.
- To enhance code completion relevance by composing context that reflects the programmer's current cognitive context.
- To address privacy concerns by ensuring all model inference occurs locally on the user's device.
- To improve the quality of single-line code suggestions without relying on cloud-based models.
- To explore context augmentation techniques that improve model performance without increasing model size.
Proposed method
- Pre-processes source code by removing whitespace, comments, and normalizing indentation using special tokens for scope changes.
- Applies BPE tokenization to the cleaned code and file path, combining them with special tokens to form a structured prompt.
- Constructs the context by concatenating file extension, file path, and code above the caret, ensuring it fits within the model's maximum context length.
- Uses special tokens like <LANG_SEP_CHAR> and <METAINFO_SEP_CHAR> to separate semantic components in the input prompt.
- Implements a strategy to reorganize class methods and functions to place relevant code fragments closer to the caret position.
- Employs a GPT-like and LLaMA-like autoregressive Transformer model for autoregressive token generation based on the composed context.
Experimental results
Research questions
- RQ1How can context composition be optimized to maximize relevance and performance in on-device code completion systems?
- RQ2What is the impact of reordering code fragments (e.g., moving methods closer to the caret) on code completion quality?
- RQ3Which file-level context sources (e.g., recently opened files, adjacent tabs) yield the most relevant context for code generation?
- RQ4How effective are retrieval-augmented or context-enrichment techniques when constrained to small, on-device models?
- RQ5What are the most effective prompt engineering strategies for compact models under 1B parameters in code completion?
Key findings
- The context-composing approach significantly improves the relevance of full-line code completion suggestions in real-world usage.
- A/B testing with hundreds of real Python developers confirmed the usefulness of the Full Line Code Completion feature in production.
- The approach achieved a measurable 10% increase in target metrics during offline experiments with retrieval-augmented context.
- Rearranging code fragments to place relevant methods closer to the caret did not yield measurable improvements, despite aligning with developer intuition.
- Retrieval-augmented generation and context enrichment from recently opened or adjacent files show strong potential for future improvements.
- On-device inference with a model under 1B parameters remains feasible and efficient, enabling low-latency, privacy-preserving code completion.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.