Neural Code Completion Re-ranking via Static Analysis

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Existing software development environments face inefficiencies in code completion systems that require significant memory and computational resources, often generating irrelevant suggestions, which can slow down development and increase errors.

Innovation Solution

A neural code completion system that uses a static analyzer to generate valid candidate suggestions and re-ranks them using neural components, improving speed, memory efficiency, and coverage without relying on machine learning for generation, thus achieving 90% recall in top candidates.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Reliability

If a neural code completion system generates code suggestions using machine learning techniques, then the relevance and accuracy of suggestions improve, but memory consumption and computational overhead increase significantly

Engineering Contradiction:
Improverelevance of code suggestionsVSAvoidmemory consumption
Core Design Contradiction:
ReliabilityVSQuantity of substance

Solution Approach 1:

The system divides the code completion task into two independent stages: (1) a static analyzer generates all syntactically valid candidate completions without using machine learning, and (2) a lightweight neural re-ranker scores and ranks these pre-generated candidates. This segmentation allows the heavy lifting of candidate generation to be done by an efficient non-ML approach, while the neural network only performs lightweight scoring on a limited set of candidates, dramatically reducing memory consumption while maintaining suggestion relevance.

Inventive Principle:
Principle #1Segmentation

Solution Approach 2:

The patent introduces an intermediary static analyzer that bridges between the code context and the neural re-ranker. The static analyzer acts as a filter that pre-processes the code context to generate only syntactically valid candidates, which then serve as input to the neural re-ranker. This intermediary component eliminates the need for the neural network to learn syntactic rules from scratch, reducing the computational burden and memory requirements of the machine learning component while preserving accuracy.

Inventive Principle:
Principle #24Intermediary (Mediator)

2Adaptability or versatility

If a code completion system uses a comprehensive candidate generation approach, then the coverage of possible completions improves, but the time to generate suggestions increases

Engineering Contradiction:
Improvecoverage of completionsVSAvoidtime to generate suggestions
Core Design Contradiction:
Adaptability or versatilityVSLoss of time

Solution Approach 1:

The static analyzer performs preliminary action by generating all syntactically valid candidate completions before the neural re-ranker processes them. This pre-generation step ensures comprehensive coverage of possible completions is achieved through efficient static analysis rather than exhaustive neural search, allowing the neural component to focus only on ranking rather than generation, thus reducing overall time while maintaining coverage.

Inventive Principle:
Principle #10Preliminary action

3Quantity of substance

If a code completion system relies on static analysis alone, then memory efficiency improves, but the ability to handle unseen code and provide relevant suggestions decreases

Engineering Contradiction:
Improvememory efficiencyVSAvoidcoverage in unseen code
Core Design Contradiction:
Quantity of substanceVSAdaptability or versatility

Solution Approach 1:

The system merges two complementary approaches: static analysis for generating syntactically valid candidates and neural re-ranking for assessing semantic relevance. The static analyzer ensures memory efficiency by using rule-based candidate generation, while the neural re-ranker adds adaptability to unseen code by learning from training data. The combination achieves both memory efficiency and improved coverage in unseen code scenarios.

Inventive Principle:
Principle #5Merging (Combining)

Solution Approach 2:

The patent changes the functional parameters of the neural network from generating candidates (high computational demand) to re-ranking candidates (low computational demand). This parameter change in the neural network's task scope allows the system to maintain memory efficiency while gaining the adaptability benefits of machine learning for handling unseen code patterns.

Inventive Principle:
Principle #35Parameter changes

Data Source

PatentUS11307831B2Neural code completion via re-ranking
Publication Date: 2022.04.19 MICROSOFT TECHNOLOGY LICENSING LLC
  • US11307831B2 patent drawing
  • US11307831B2 patent drawing
  • US11307831B2 patent drawing

AI summary

A code completion system uses neural components to rank the unordered list of code completion candidates generated from an existing static analyzer. The candidates represent the next sequence of tokens likely to complete a partially-formed program element as a developer is typing in a software development tool. A re-ranking component generates a ranked order of the candidates based on a context embedding of the code context and candidate embeddings of the candidates, where both embeddings are based a common token encoding.