Binary Code Profiling Using Function Density for Cache Optimization

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Existing code profiling techniques, such as instrumentation and special hardware, often fail to provide significant optimization for PHP code, leading to performance issues due to inaccurate results and Heisenbugs, and do not effectively improve execution efficiency.

Innovation Solution

Density-based code profiling, which computes the frequency of execution of functions and data structures relative to their size, rearranges binary code to place denser functions and data structures at the beginning, minimizing cache and TLB misses by loading them into processor caches and the translation lookaside buffer (TLB) first.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Measurement precision

If instrumentation technique is used to profile code, then execution-related information can be collected, but it requires access to source code, causes performance changes, and may lead to inaccurate results and Heisenbugs

Engineering Contradiction:
Improveprofiling accuracyVSAvoidprogram stability
Core Design Contradiction:
Measurement precisionVSReliability

Solution Approach 1:

The patent uses hardware performance counters to copy execution information from the CPU to external storage without modifying the original program. This creates a faithful replica of execution data (function call frequencies, instruction counts) while leaving the program unchanged, thus maintaining both measurement accuracy and program stability

Inventive Principle:
Principle #26Copying

Solution Approach 2:

The patent introduces hardware performance counters as an intermediary between the CPU and the profiling system. These counters act as a mediator that captures execution information without requiring direct access to source code or modification of the program, eliminating the Heisenbug problem while maintaining measurement precision

Inventive Principle:
Principle #24Intermediary (Mediator)

2Productivity

If code is arranged in traditional order, then compilation is simpler, but cache and TLB misses increase leading to slower execution

Engineering Contradiction:
Improveexecution speedVSAvoidcache miss penalty
Core Design Contradiction:
ProductivityVSLoss of energy

Solution Approach 1:

The patent performs preliminary analysis of execution frequencies and function sizes before code arrangement, using hardware counters to collect data during a profiling phase. This preliminary information gathering enables the subsequent optimization of code layout to minimize cache misses during actual execution

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The patent applies different arrangement strategies to different parts of the code based on their characteristics. Dense functions (high execution frequency relative to size) are placed in cache-friendly locations, while less dense functions are placed elsewhere. This local optimization of code placement based on individual function properties improves cache utilization and execution speed

Inventive Principle:
Principle #3Local quality

3Loss of time

If frequently executed functions are optimized, then execution time may improve, but the optimization is not significant for PHP code

Engineering Contradiction:
Improveexecution timeVSAvoidoptimization effectiveness
Core Design Contradiction:
Loss of timeVSProductivity

Solution Approach 1:

The patent changes the optimization parameter from simple execution frequency to a density metric that combines execution frequency with function size. This parameter transformation reveals that small, frequently executed functions are the true performance bottlenecks, leading to more effective optimization than traditional frequency-based approaches

Inventive Principle:
Principle #35Parameter changes

Data Source

PatentUS9342283B2Profiling binary code based on density
Publication Date: 2016.05.17 META PLATFORMS INC
  • US9342283B2 patent drawing
  • US9342283B2 patent drawing
  • US9342283B2 patent drawing

AI summary

The technology is directed to profiling binary code based on a computed “density” of functions in the code. The density of a function can be computed as the frequency of execution of the function divided by the size of the function. Functions that execute more often and are smaller in size (“dense functions”) are moved towards the “front” (e.g., beginning) of the binary code. The frequency of execution can be measured at runtime using a performance measurement tool without requiring modification of the binary code or corresponding source code. After density is computed (e.g., over a period of time) for functions, it can be used to cause linkers to rearrange the binary code to place denser functions closer to the “front” of the binary code. By loading denser functions first (e.g., into processor caches and translation lookaside buffer (“TLB”)), the technology reduces cache and TLB misses, and thereby improves system performance.