Compiler Conditional Reordering for Code Execution Speed

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Programmers often write compound conditionals with suboptimal orderings, leading to inefficient code execution due to unawareness of the computational costs of different conditions, resulting in wasted processing resources and slower execution.

Innovation Solution

A computing device is configured to receive source code with compound conditionals, determine orderings that satisfy legality constraints, and reorder conditions to achieve the lowest estimated computational cost, using a compiler to convert source code into assembly code while preventing errors and optimizing processing.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Productivity

If conditions are evaluated in the order presented in the source code, then the code structure is simple and easy to understand, but computationally expensive conditions may be evaluated unnecessarily, wasting processing resources and slowing execution

Engineering Contradiction:
Improvecode execution speedVSAvoidcompiler optimization complexity
Core Design Contradiction:
ProductivityVSDevice complexity

Solution Approach 1:

The compiler performs preliminary analysis of condition computational costs and reorders them before code generation. By evaluating and sorting conditions based on their estimated computational expense in advance, the compiler ensures that least expensive conditions are evaluated first, avoiding unnecessary computation of expensive conditions while maintaining simple source code structure.

Inventive Principle:
Principle #10Preliminary action

2Loss of energy

If the compiler reorders conditions to minimize computational cost, then processing efficiency improves, but the complexity of the compilation process increases

Engineering Contradiction:
Improveprocessing resource wasteVSAvoidcompiler complexity
Core Design Contradiction:
Loss of energyVSDevice complexity

Solution Approach 1:

The compiler changes the parameter of condition evaluation order based on computational cost analysis. By introducing a cost metric parameter for each condition and sorting conditions according to this parameter, the compiler transforms the fixed source code order into an optimized execution order, reducing processing resource waste while adding systematic analysis capability.

Inventive Principle:
Principle #35Parameter changes

Solution Approach 2:

The compiler creates temporary cost estimation models and ordering arrangements during compilation that are discarded after use. These intermediate structures (cost assignments, ordering permutations) are disposable artifacts used only for optimization purposes and do not persist in the final executable, minimizing the lasting complexity burden.

Inventive Principle:
Principle #27Cheap short-living objects (Disposable)

3Productivity

If programmers manually optimize condition orderings, then execution efficiency can be improved, but the programming becomes more difficult and error-prone

Engineering Contradiction:
Improvecode execution efficiencyVSAvoidprogramming ease
Core Design Contradiction:
ProductivityVSEase of operation

Solution Approach 1:

The compiler performs self-service optimization by automatically analyzing condition costs and reordering them without programmer intervention. This transfers the optimization burden from the programmer to the compiler, maintaining programming simplicity while achieving execution efficiency through automated analysis and transformation of condition orderings.

Inventive Principle:
Principle #25Self-service

Data Source

PatentUS12197310B2Compound conditional reordering for faster short-circuiting
Publication Date: 2025.01.14 MICROSOFT TECHNOLOGY LICENSING LLC
  • US12197310B2 patent drawing
  • US12197310B2 patent drawing
  • US12197310B2 patent drawing

AI summary

A computing device is provided, including a processor configured to receive source code at a compiler. The source code may include at least one compound conditional having a plurality of conditions. For each condition of the plurality of conditions, the source code may further include a respective code block including instructions to evaluate the condition. For each ordering of a plurality of orderings of the plurality of conditions, the processor may determine that the ordering satisfies one or more legality constraints. For each ordering of the plurality of orderings that satisfy the one or more legality constraints, the processor may determine a respective estimated computational cost for that ordering. The processor may reorder the plurality of conditions to have an ordering that has a lowest estimated computational cost of the plurality of orderings that satisfy the one or more legality constraints.