Skip to content

Commit

Permalink
Improve on Union performance (#176)
Browse files Browse the repository at this point in the history
Preallocating the HashSet allows for less CPU and memory usage then
using Linq.Union.
  • Loading branch information
nathanmascitelli authored Nov 22, 2023
1 parent 3378109 commit b51b051
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/Unleash/DefaultUnleash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,12 @@ private bool DetermineIsEnabledAndStrategy(
}
else
{
strategy = featureToggle.Strategies
.FirstOrDefault(s =>
GetStrategyOrUnknown(s.Name)
.IsEnabled(s.Parameters, enhancedContext, ResolveConstraints(s).Union(s.Constraints))
);
strategy = featureToggle.Strategies.FirstOrDefault(s =>
{
var uniqueConstraints = new HashSet<Constraint>(ResolveConstraints(s));
uniqueConstraints.UnionWith(s.Constraints);
return GetStrategyOrUnknown(s.Name).IsEnabled(s.Parameters, enhancedContext, uniqueConstraints);
});
}

if (featureToggle.Dependencies.Any() && !ParentDependenciesAreSatisfied(featureToggle, enhancedContext))
Expand Down

0 comments on commit b51b051

Please sign in to comment.