Closed nathanmascitelli closed 10 months ago
Thank you for your contribution @nathanmascitelli! we'll have a look!
Hey @nathanmascitelli, thanks so much for this contribution, this is awesome!
Kinda curious though, I feel like the numbers here are a bit extreme, any chance you could share how many feature toggles you have in your Unleash instance? I'm just trying to find out if the SDK here is chewing through an excessive amount of memory or if you genuinely have a lot of toggles and this is just streamlining that
@sighphyre we have 326 flags at the moment. I assumed this was a large number and that's why this hasn't been a problem for others. We are working on reducing the number of flags.
@nathanmascitelli Oh. Oh dear. No that's not a large number at all, that's well within reason for the computations (might be a little bit large for users to understand whats going on with their flags in their system though). For some context here, a similar sized feature set uses less than 15MB of RAM in our Edge server under load. And roughly a quarter of the numbers you're reporting for 40K toggles
Gosh time for some optimisation. Thank you so much for the information!
@sighphyre sorry I'm not sure I follow your last statement. Are you saying its time for optimization of the dotnet client or my application? If my application, can you give some guidence on what optimizations you're thinking of? We are just calling IsEnabled
on the IUnleash
client created by UnleashClientFactory
. Admittedly maybe we are calling it too much or something...
@nathanmascitelli Sorry! That was super unclear of me! I mean that the Unleash team probably needs to look this one over and see where the SDK is using these resources. Gut feel is that this isn't your application
@sighphyre oh I would never count me out for doing something silly :). Jokes asside, thanks for clearing that up. I'm happy to help if I can.
Description
In looking at our application which uses the dotnet Unleash client we found that a large amount of memory was being allocated by the client:
Looking at the callstack the
Union
call inDefaultUnleash.DetermineIsEnabledAndStrategy
is what is allocating so many arrays. These allocations can be reduced by replacing theUnion
call with a preallocatedHashSet
(which is whatUnion
uses).Type of change
How Has This Been Tested?
The following BenchmarkDotnet code was used to validate that this was better performing:
So my proposed change uses less CPU and memory then the current
Union
.