configcat / .net-sdk

ConfigCat SDK for .NET. ConfigCat is a hosted feature flag service: https://configcat.com. Manage feature toggles across frontend, backend, mobile, desktop apps. Alternative to LaunchDarkly. Management app + feature flag SDKs.
https://configcat.com/docs/sdk-reference/csharp
Other
29 stars 8 forks source link

Reduce JSON deserialization calls, add benchmarks #24

Closed z4kn4fein closed 3 years ago

z4kn4fein commented 3 years ago

Describe the purpose of your pull request

Reducing the number of JSON deserialization calls by caching the last deserialized object in memory. Now, the deserialization is called only when the retrieved JSON string differs from the latest cached one.

Performance benchmark:

| Method |       Mean |     Error |    StdDev | Ratio |  Gen 0 | Allocated |
|------- |-----------:|----------:|----------:|------:|-------:|----------:|
|    Old | 109.080 us | 1.7396 us | 1.6272 us |  1.00 | 2.9297 |     25 KB |
|    New |   7.434 us | 0.1480 us | 0.1384 us |  0.07 | 0.9308 |      8 KB |

Related issues (only if applicable)

22

Requirement checklist (only if applicable)

codecov[bot] commented 3 years ago

Codecov Report

Merging #24 (fa35873) into master (26b2edd) will increase coverage by 0.02%. The diff coverage is 95.91%.

:exclamation: Current head fa35873 differs from pull request most recent head d6ac458. Consider uploading reports for the commit d6ac458 to get more accurate results Impacted file tree graph

@@            Coverage Diff             @@
##           master      #24      +/-   ##
==========================================
+ Coverage   96.89%   96.91%   +0.02%     
==========================================
  Files          27       27              
  Lines         708      713       +5     
  Branches       71       73       +2     
==========================================
+ Hits          686      691       +5     
  Misses         12       12              
  Partials       10       10              
Impacted Files Coverage Δ
src/ConfigCatClient/HttpConfigFetcher.cs 96.51% <92.30%> (-0.05%) :arrow_down:
src/ConfigCatClient/ConfigCatClient.cs 92.42% <100.00%> (-0.06%) :arrow_down:
src/ConfigCatClient/ConfigDeserializer.cs 100.00% <100.00%> (ø)
src/ConfigCatClient/Evaluate/RolloutEvaluator.cs 97.67% <100.00%> (+0.01%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 26b2edd...d6ac458. Read the comment docs.

z4kn4fein commented 3 years ago

Update:

Replaced .GetHashCode() with MurmurHash3. Far less chance for hashes to collide.

Updated benchmark:

| Method |       Mean |     Error |    StdDev | Ratio |  Gen 0 |  Gen 1 | Allocated |
|------- |-----------:|----------:|----------:|------:|-------:|-------:|----------:|
|    Old | 107.847 us | 0.4968 us | 0.4647 us |  1.00 | 2.9297 | 0.1221 |     25 KB |
|    New |   6.921 us | 0.0347 us | 0.0325 us |  0.06 | 1.3809 | 0.0076 |     11 KB |