Thread-local return structure reuse for async state machines

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Existing asynchronous programming systems incur inefficiencies due to the repeated allocation and deallocation of return data structures in computing environments, particularly when asynchronous functions return synchronously, leading to suboptimal resource utilization and performance bottlenecks.

Innovation Solution

Implementing a thread-local return data structure reuse mechanism, where a pre-allocated return data structure is populated and reused for future synchronous returns within the same thread, avoiding the need for repeated allocation and deallocation in the heap.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Reliability

If a new Task object is allocated for every asynchronous function return, then the system ensures data integrity and thread safety, but heap allocation overhead increases and performance decreases

Engineering Contradiction:
Improvedata integrityVSAvoidperformance
Core Design Contradiction:
ReliabilityVSProductivity

Solution Approach 1:

The system pre-allocates Task objects in a pool before they are needed. When an asynchronous function returns, the runtime can immediately assign a pre-existing Task object from the pool, avoiding heap allocation overhead while ensuring data integrity through proper initialization and tracking of each Task's state

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

Instead of allowing Task objects to be garbage collected after use, the system recovers them by adding completed Task objects back to the pre-allocated pool. This recovery mechanism allows the same Task objects to be reused multiple times, eliminating continuous heap allocation and deallocation while maintaining reliability through proper state reset

Inventive Principle:
Principle #34Discarding and recovering

2Productivity

If pre-allocated Task objects are used for common values, then heap allocation is avoided for frequent cases, but the system complexity increases due to pool management

Engineering Contradiction:
Improveallocation efficiencyVSAvoidsystem complexity
Core Design Contradiction:
ProductivityVSDevice complexity

Solution Approach 1:

The pre-allocated Task objects are designed to be universal and multi-functional. Each Task object in the pool can serve multiple asynchronous operations by being reset and reused. The Task objects contain generic structures that can hold different return types (Task, Task<T>, Task<TResult>), making them universally applicable across various async scenarios without requiring separate pools for each type

Inventive Principle:
Principle #6Universality (Multi-functionality)

Solution Approach 2:

The system manages Task objects by changing their state parameters rather than creating new objects. When a Task is completed, its state parameters (completion status, result data, exception information) are updated and then reset for reuse. This parameter-based state management allows the same physical object to represent different logical states, reducing the need for object creation while maintaining system reliability

Inventive Principle:
Principle #35Parameter changes

3Ease of manufacture

If Task objects are created on the heap for each return, then dynamic memory management is simplified, but resource utilization becomes suboptimal due to frequent allocation and deallocation

Engineering Contradiction:
Improvememory management simplicityVSAvoidresource utilization
Core Design Contradiction:
Ease of manufactureVSQuantity of substance

Solution Approach 1:

The Task pool implements a self-service mechanism where completed Task objects automatically return to the pool for reuse. The runtime system manages the pool automatically without requiring manual intervention, and the Task objects themselves track their own completion status and readiness for reuse. This self-managing approach simplifies memory management while optimizing resource utilization by keeping Task objects in memory for immediate reuse

Inventive Principle:
Principle #25Self-service

Data Source

PatentEP4204960B1Thread-local return structure for asynchronous state machine
Publication Date: 2025.01.15 MICROSOFT TECHNOLOGY LICENSING LLC
  • EP4204960B1 patent drawingFigure 1
  • EP4204960B1 patent drawingFigure 2
  • EP4204960B1 patent drawingFigure 3

AI summary

Reuse of a thread-local return data structure to prevent a return data structure from being allocated every time asynchronous functions return. The system returns thread operation from the asynchronous function back to the caller function in a manner that the return data structure can be reused for future asynchronous function returns within that same thread. To do so, the system first accesses data that was generated by the asynchronous function in response to the caller function placing the function call to the asynchronous function. To determine if reuse is appropriate, the system determines that the caller function will use the return data structure as populated only once. If so, the system populates the reusable thread-local return data structure and returns that data structure to the caller.