Skip to content

Conversation

@gmanvel
Copy link

@gmanvel gmanvel commented Dec 4, 2025

Description

Removed Cache benchmark as it's not adding much value, it benchmarks operations on in memory cache.
Added test coverage for FastLabelPropagationCommunityDetector.AssignLabels method.
Applied perf/allocation improvements to AssignLabels method.

Proposed Changes

Applying small tweaks to reduce allocations, by using random.shuffle to shuffle in-place instead of creating a new list. Also moved labelWeights dictionary creation outside of the loop to reduce allocations further.

BenchmarkDotNet results:

Method MaxIterations Mean Ratio Gen0 Gen1 Gen2 Allocated Alloc Ratio
SmallGraph 10 137.1 μs 1.00 43.9453 3.9063 - 360.23 KB 1.00
SmallGraphOptimized 10 107.0 μs 0.78 19.7754 1.7090 - 161.79 KB 0.45
MediumGraph 10 4,409.8 μs 32.17 929.6875 460.9375 - 7622.17 KB 21.16
MediumGraphOptimized 10 3,501.4 μs 25.54 292.9688 128.9063 - 2412.64 KB 6.70
LargeGraph 10 51,760.4 μs 377.57 8300.0000 1400.0000 400.0000 65432.8 KB 181.64
LargeGraphOptimized 10 48,501.6 μs 353.80 3181.8182 1363.6364 363.6364 23987.92 KB 66.59
SmallGraph 20 133.8 μs 1.00 43.9453 3.9063 - 360.23 KB 1.00
SmallGraphOptimized 20 109.6 μs 0.82 19.7754 1.7090 - 161.79 KB 0.45
MediumGraph 20 4,468.4 μs 33.40 929.6875 460.9375 - 7622.17 KB 21.16
MediumGraphOptimized 20 3,551.9 μs 26.55 292.9688 128.9063 - 2412.64 KB 6.70
LargeGraph 20 53,121.9 μs 397.07 8300.0000 1400.0000 400.0000 65432.76 KB 181.64
LargeGraphOptimized 20 49,651.3 μs 371.13 3200.0000 1300.0000 400.0000 23987.96 KB 66.59
SmallGraph 40 141.4 μs 1.00 43.9453 3.9063 - 360.23 KB 1.00
SmallGraphOptimized 40 109.8 μs 0.78 19.7754 1.7090 - 161.79 KB 0.45
MediumGraph 40 4,637.3 μs 32.79 929.6875 460.9375 - 7622.17 KB 21.16
MediumGraphOptimized 40 3,567.2 μs 25.22 292.9688 128.9063 - 2412.64 KB 6.70
LargeGraph 40 53,164.4 μs 375.88 8300.0000 1400.0000 400.0000 65432.76 KB 181.64
LargeGraphOptimized 40 49,436.0 μs 349.52 3200.0000 1300.0000 400.0000 23988.3 KB 66.59

Which are big in allocation improvement & up to 20 % performance improvement.

Iterations Graph Size Mean Improvement (%) Allocation Improvement (%)
10 Small 21.9% 55.1%
10 Medium 20.6% 68.3%
10 Large 6.3% 63.3%
20 Small 18.1% 55.1%
20 Medium 20.5% 68.3%
20 Large 6.5% 63.3%
40 Small 22.4% 55.1%
40 Medium 23.1% 68.3%
40 Large 7.0% 63.3%

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

@codecov
Copy link

codecov bot commented Dec 4, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.24%. Comparing base (41b89ca) to head (feb6294).
⚠️ Report is 12 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main       #5      +/-   ##
==========================================
- Coverage   75.34%   75.24%   -0.11%     
==========================================
  Files         115      115              
  Lines        4734     4751      +17     
  Branches      797      798       +1     
==========================================
+ Hits         3567     3575       +8     
- Misses        851      861      +10     
+ Partials      316      315       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@KSemenenko
Copy link
Member

I absolutely love your work! Thanks a lot!

@KSemenenko KSemenenko merged commit a2506f8 into managedcode:main Dec 6, 2025
4 of 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