Static Analysis for Dynamic Code Optimization

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Existing compilers, particularly those for Android applications, struggle to generate high-quality code due to the limitations of trace-based just-in-time compilers, which hinder deep optimization and increase execution time, especially when dealing with dynamic features like reflection and runtime type checking.

Innovation Solution

A static analysis mechanism predicts the likelihood of program elements being used during execution, generating native code ahead-of-time with confidence indicators to determine which optimizations to perform and what code to include, thereby reducing execution speed and size.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Adaptability or versatility

If trace-based just-in-time compilation is used to support dynamic features, then flexibility and runtime adaptability are improved, but execution time increases and deep optimization is hindered

Engineering Contradiction:
Improveruntime adaptabilityVSAvoidexecution time
Core Design Contradiction:
Adaptability or versatilityVSLoss of time

Solution Approach 1:

The patent performs preliminary static analysis during the ahead-of-time compilation phase to pre-determine which code paths are likely to be executed. By analyzing the program before runtime and preparing optimized native code in advance based on static predictions, the system eliminates the need for trace-based JIT compilation at runtime, thereby reducing execution time while maintaining support for dynamic features through confidence indicators that guide which code to optimize ahead-of-time.

Inventive Principle:
Principle #10Preliminary action

2Productivity

If ahead-of-time compilation is used to reduce execution time, then native code generation speed is improved, but code size increases and deep optimization is limited due to uncertainty about runtime behavior

Engineering Contradiction:
Improvenative code generation speedVSAvoidnative code size
Core Design Contradiction:
ProductivityVSWeight of stationary object

Solution Approach 1:

The patent applies local quality by differentiating between various regions of code based on confidence indicators. Instead of uniformly including or optimizing all code paths, the system selectively applies optimization and native code generation only to those code regions with high confidence indicators. This localized approach ensures that only necessary code is generated and optimized ahead-of-time, reducing overall native code size while maintaining fast execution for critical paths.

Inventive Principle:
Principle #3Local quality

Solution Approach 2:

The patent changes the parameter of code inclusion by using confidence indicators as a threshold criterion. Code paths are transformed from being universally included to being conditionally included based on their confidence scores. This parameter change allows the compiler to dynamically adjust which code segments receive ahead-of-time compilation treatment, optimizing the balance between code size and execution speed.

Inventive Principle:
Principle #35Parameter changes

3Manufacturing precision

If static analysis is performed to predict program element usage, then code optimization is improved and native code size is reduced, but analysis complexity and computational overhead increase

Engineering Contradiction:
Improvecode optimization qualityVSAvoidanalysis complexity
Core Design Contradiction:
Manufacturing precisionVSDevice complexity

Solution Approach 1:

The patent applies partial action by performing static analysis selectively rather than comprehensively on all program elements. The analysis focuses on generating confidence indicators for specific code paths that are most likely to be executed, rather than attempting to analyze and optimize every possible runtime scenario. This partial analysis approach reduces computational overhead and complexity while still achieving significant optimization benefits for the critical code paths.

Inventive Principle:
Principle #16Partial or excessive action

Data Source

PatentEP3642709B1Differentiated static analysis for dynamic code optimization
Publication Date: 2023.04.26 MICROSOFT TECHNOLOGY LICENSING LLC
  • EP3642709B1 patent drawingFigure 1
  • EP3642709B1 patent drawingFigure 2
  • EP3642709B1 patent drawingFigure 3

AI summary

A mechanism for generating optimized native code for a program having dynamic behavior uses a static analysis of the program to predict the likelihood that different elements of the program are likely to be used when the program executes. The static analysis is performed prior to execution of the program and marks certain elements of the program with confidence indicators that classify the elements with either a high level of confidence or a low level of confidence. The confidence indicators are then used by an ahead-of-time native compiler to generate native code and to optimize the code for faster execution and/or a smaller-sized native code.