When calling IUnleash.IsEnabled we end up cloning the UnleashContext. This cloning is not needed and expensive since the entire Properties dictionary needs to be cloned. This case removes the cloning.
Fixes #186
Type of change
Please delete options that are not relevant.
[x] Bug fix (non-breaking change which fixes an issue)
How Has This Been Tested?
Using the following benchmark (note IsEnabled2 calls the code proposed in this PR):
[MemoryDiagnoser]
public class Benchmark
{
readonly UnleashContext context = new();
readonly DefaultUnleash client = new(new UnleashSettings());
public Benchmark()
{
// Remove this loop to test empty properties
for (int i = 0; i < 10; i++)
{
context.Properties.Add(i.ToString(), i.ToString());
}
}
[Benchmark(Baseline = true)]
public bool Current() => client.IsEnabled("Moo", context);
[Benchmark]
public bool NoClone() => client.IsEnabled2("Moo", context);
}
Description
When calling
IUnleash.IsEnabled
we end up cloning theUnleashContext
. This cloning is not needed and expensive since the entireProperties
dictionary needs to be cloned. This case removes the cloning.Fixes #186
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Using the following benchmark (note
IsEnabled2
calls the code proposed in this PR):The following results were obtained:
Empty Properties
10 Elements in Properties