Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSharp Performance: don't decrease list capacities when reusing clipper objects #750

Merged
merged 1 commit into from
Dec 19, 2023

Conversation

SebastianDirks
Copy link
Contributor

CSharp Performance: when reusing clipper objects, currently clipper sets the internal lists capacity, even if the capacity is already sufficient. This causes C# to drop the currently allocated array and create a new, smaller one (If clipper is not reused this is fine).

This merge request contains changes that check if the capacity is sufficient before setting it to reduce allocations.

I have conducted a benchmark (using BenchmarkDotNet) of my application that reuses clipper objects. This small change reduces allocations by 15% and also slightly improves runtimes.

Method Scenario solutionsToCalc Mean Error StdDev Gen0 Gen1 Allocated
NestScenarioWithStartHeuristic 3DIPP-Instance-01259 4 6.320 s 0.1240 s 0.1656 s 14000.0000 1000.0000 25.73 GB
NestScenarioWithStartHeuristic - no Capacity decrease 3DIPP-Instance-01259 4 6.221 s 0.1122 s 0.1050 s 12000.0000 1000.0000 21.93 GB

…ets the internal lists capacity, even if the capacity already sufficient. This causes C# to drop the currently allocated array and create a new, smaller one.

This changes check if the capacity is sufficient before setting it to reduces allocations.
@AngusJohnson AngusJohnson merged commit 2d7564f into AngusJohnson:main Dec 19, 2023
7 checks passed
jiajuncccc added a commit to jiajuncccc/Clipper2 that referenced this pull request Dec 20, 2023
* remotes/upstream/main:
  Minor code tidy of variable offset example
  CSharp Performance: when reusing clipper objects, currently clipper sets the internal lists capacity, even if the capacity already sufficient. This causes C# to drop the currently allocated array and create a new, smaller one. (AngusJohnson#750)
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