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

Remove some allocations related to GudelineSet and DoubleCollection #10310

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

h3xds1nz
Copy link
Member

@h3xds1nz h3xds1nz commented Jan 17, 2025

Description

  • Accept stack-allocated arrays internally for GudelineSet.
  • Accept params for DoubleCollection with pre-allocated capacity in FrugalStructList<T>.
  • Use them in the framework code.

Sample benchmark for GuidelineSet creation

Method Mean [ns] Error [ns] StdDev [ns] Gen0 Code Size [B] Allocated [B]
ORIGINAL 298.1 ns 4.57 ns 4.28 ns 0.0329 866 B 552 B
PR__EDIT 257.5 ns 3.55 ns 3.15 ns 0.0281 3,842 B 472 B
[Benchmark]
public GuidelineSet Original() => new GuidelineSet([4.5, 6.5], [4.5, 6.5]);

[Benchmark]
public GuidelineSet PR__EDIT() => new GuidelineSet(new double[] { 4.5, 6.5 }, new double[] { 4.5, 6.5 });

Customer Impact

Improved performance, decreased allocations.

Regression

No.

Testing

Local build.

Risk

Low, just swaps from heap arrays to stack arrays. Part of the speed up comes from the fact the new DoubleCollection doesn't check the thread in params ctor as it makes no sense (further backed with all the code comments) and it can therefore get inlined.

Microsoft Reviewers: Open in CodeFlow

@h3xds1nz h3xds1nz requested review from a team as code owners January 17, 2025 19:34
@dotnet-policy-service dotnet-policy-service bot added PR metadata: Label to tag PRs, to facilitate with triage Community Contribution A label for all community Contributions labels Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community Contribution A label for all community Contributions PR metadata: Label to tag PRs, to facilitate with triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants