Polly icon indicating copy to clipboard operation
Polly copied to clipboard

Pooling of Context instances

Open martintmk opened this issue 3 years ago • 0 comments

Is your feature request related to a specific problem? Or an existing feature? Please describe.

We have noticed increased allocations related to creating the Context object. This can be easily avoided if Pollu provides built-in support for pooling or at least slightly change the internal implementation of Context so we can easily reset it to default state.

Currently, this is not achievable because of these read-only properties:

  • OperationId
  • CorrelationId

Describe your proposed or preferred solution:

We want to extend the Context API with the following static methods:

public static Context Get();
public static Context Get(string operationName);
public static void Return(Context context);

Alternatively, we can introduce a new ContextPool static class.

The pool can be also used internally to improve Polly performance.

Describe any alternative options you've considered:

Simpler solution is to make the following changes to Context class:

protected Guid? CorrelationIdField { get; protected set; }
public string OperationKey { get; protected set; }

We would just derive from Context and handle the pooling ourselves.

Any additional info?

For pooling support, we need implementation of the pool, and we can either:

martintmk avatar Aug 11 '22 12:08 martintmk