Skip to content

Conversation

@gmanvel
Copy link

@gmanvel gmanvel commented Dec 2, 2025

Description

Added benchmarks to cover some parts of the system. The intention is to have perf benchmarks & test coverage so that code optimizations can be properly applied and regressions (if any) captured.

Related Issues

N/A

Proposed Changes

  • Adding Benchmarks project and BenchmarkDotNet benchmarks to cover some parts
  • Unit tests to cover Hashing functionality
  • Optimized implementation of GenerateSha512Hash method

Tested to ensure optimized version generates same hash as existing one. Ran current/optimized version side by side. Pasting BenchmarkDotNet results below

Method Mean Error StdDev Ratio RatioSD Gen0 Gen1 Allocated Alloc Ratio
HashSmallProperties 360.3 ns 2.49 ns 2.33 ns 1.00 0.01 0.1011 - 848 B 1.00
HashSmallPropertiesOptimized 256.4 ns 2.71 ns 2.40 ns 0.71 0.01 0.0525 - 440 B 0.52
HashMediumProperties 340.3 ns 1.46 ns 1.22 ns 0.94 0.01 0.1817 - 1520 B 1.79
HashMediumPropertiesOptimized 495.0 ns 3.95 ns 3.70 ns 1.37 0.01 0.0525 - 440 B 0.52
HashLargeProperties 1,099.8 ns 7.26 ns 6.79 ns 3.05 0.03 0.6943 0.0038 5816 B 6.86
HashLargePropertiesOptimized 1,898.8 ns 7.06 ns 6.61 ns 5.27 0.04 0.0515 - 440 B 0.52
HashLargeValueProperties 4,126.8 ns 48.73 ns 45.58 ns 11.45 0.14 3.9063 0.1907 32752 B 38.62
HashLargeValuePropertiesOptimized 3,487.1 ns 29.87 ns 27.94 ns 9.68 0.10 0.0496 - 440 B 0.52
HashWithTuples 358.9 ns 2.15 ns 2.01 ns 1.00 0.01 0.2027 - 1696 B 2.00

As can be seen memory allocations are capped at 440 B regardless of the fields' payload. However, this comes with a trade off of perf regression for medium & large properties. For small & large values performance actually improves. However, suggested changes are mainly to improve allocations.

Scenario Original Alloc Optimized Alloc Absolute Savings % Reduction
Small 848 B 440 B 408 B 51.9%
Medium 1,520 B 440 B 1,080 B 71.1%
Large 5,816 B 440 B 5,376 B 92.4%
LargeVal 32,752 B 440 B 32,312 B 98.7%

Checklist

  • I have tested these changes locally.
  • I have reviewed the code changes.
  • I have updated the documentation (if necessary).
  • I have added appropriate unit tests (if applicable).

Additional Notes

N/A

@KSemenenko
Copy link
Member

Thanks a lot! This is just an amazing PR!

@codecov
Copy link

codecov bot commented Dec 2, 2025

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

@KSemenenko KSemenenko merged commit 87545a2 into managedcode:main Dec 2, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants