Approximate Code Counting With Probabilistic Counter Updates

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Existing counter-based instrumentation techniques for dynamic profile-guided optimization (PGO) suffer from high computational overhead and inaccuracies in multithreaded environments due to cache contention and unsynchronized access, leading to inefficient code optimization.

Innovation Solution

Implement a counter that operates in two modes: deterministic and probabilistic, switching from deterministic mode to probabilistic mode when a threshold is reached, reducing updates by incrementing the count by a value of N with a probability of 1/N, using integer encoding to minimize file system writes and contention.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Measurement precision

If a counter updates the count by a value of 1 with probability 1 for each code portion call, then the count accuracy is high, but the computational overhead and cache contention increase significantly

Engineering Contradiction:
Improvecount accuracyVSAvoidcomputational overhead
Core Design Contradiction:
Measurement precisionVSProductivity

Solution Approach 1:

The counter performs partial updates by incrementing by a value of N with probability 1/N instead of updating by 1 with probability 1 for every code portion call. This partial action reduces the frequency of counter updates while maintaining expected value accuracy, directly addressing the contradiction between measurement precision and productivity.

Inventive Principle:
Principle #16Partial or excessive action

Solution Approach 2:

The counter changes its update parameters dynamically by switching from deterministic mode (increment by 1, probability 1) to probabilistic mode (increment by N, probability 1/N) when a threshold is reached. This parameter change allows the system to reduce computational overhead while maintaining acceptable accuracy through statistical properties.

Inventive Principle:
Principle #35Parameter changes

2Measurement precision

If the counter operates in deterministic mode updating by 1 for each call, then the count is accurate, but the cache contention and unsynchronized access problems worsen in multithreaded environments

Engineering Contradiction:
Improvecount accuracyVSAvoidcache contention
Core Design Contradiction:
Measurement precisionVSObject-affected harmful factors

Solution Approach 1:

By updating the counter less frequently (with probability 1/N instead of 1), the system reduces the number of times multiple threads contend for the same cache location, directly mitigating cache contention while maintaining statistical accuracy through the probabilistic update mechanism.

Inventive Principle:
Principle #16Partial or excessive action

3Measurement precision

If the counter updates frequently for each code portion call, then the count accuracy is maintained, but the file system writes and synchronization overhead increase

Engineering Contradiction:
Improvecount accuracyVSAvoidsynchronization overhead
Core Design Contradiction:
Measurement precisionVSLoss of time

Solution Approach 1:

The counter performs partial updates less frequently by using probability 1/N instead of deterministic updates, reducing the frequency of file system writes and synchronization operations while maintaining expected value accuracy through statistical properties.

Inventive Principle:
Principle #16Partial or excessive action

Solution Approach 2:

The counter switches from continuous deterministic updates to periodic probabilistic updates after reaching a threshold, creating a periodic action pattern that reduces synchronization overhead while maintaining acceptable accuracy through the statistical properties of the probabilistic updates.

Inventive Principle:
Principle #19Periodic action

Data Source

PatentUS12602213B2Scalable approximate counting
Publication Date: 2026.04.14 MICROSOFT TECHNOLOGY LICENSING LLC
  • US12602213B2 patent drawing
  • US12602213B2 patent drawing
  • US12602213B2 patent drawing

AI summary

Techniques for implementing an intentionally approximate counting scheme are disclosed. A code counter is accessed. The counter updates a count that is approximately representative of a number of times the code is called. The counter operates in a first mode where the counter updates the count by a value of 1 and where a probability by which the counter updates the count is set to a value of 1. The counter switches from operating in the first mode to operating in a second mode. The counter now updates the count by a value of N, where N is an integer larger than 1. The probability by which the counter updates the count is set to a value of 1/N such that, despite multiple calls being made to the code, the count is updated in accordance with the 1/N probability. The counter continues to update the count.