-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Modify Capacity growth rate to be linear instead of doubling on resize. #75708
Closed
ToddGrun
wants to merge
4
commits into
dotnet:main
from
ToddGrun:dev/toddgrun/SegmentedListGrowthRate
Closed
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6f3564b
Modify Capacity growth rate to be linear instead of doubling on resize.
ToddGrun 5a98efb
Missed header
ToddGrun 1a4eb36
Move the outer array double size allocation to only be called from Grow.
ToddGrun 7b31928
Change SegmentedArray _items array to explicitly acknowledge that it …
ToddGrun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/Tools/IdeCoreBenchmarks/SegmentedListBenchmarks_Add_SegmentCounts.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using BenchmarkDotNet.Attributes; | ||
using Microsoft.CodeAnalysis.Collections; | ||
using Microsoft.CodeAnalysis.Collections.Internal; | ||
|
||
[MemoryDiagnoser] | ||
public class SegmentedListBenchmarks_Add_SegmentCounts | ||
{ | ||
[Params(16, 256, 4096, 65536)] | ||
public int SegmentCount { get; set; } | ||
|
||
[ParamsAllValues] | ||
public bool AddExtraItem { get; set; } | ||
|
||
[Benchmark] | ||
public void AddObjectToList() | ||
=> AddToList(new object()); | ||
|
||
[Benchmark] | ||
public void AddLargeStructToList() | ||
=> AddToList(new LargeStruct()); | ||
|
||
[Benchmark] | ||
public void AddEnormousStructToList() | ||
=> AddToList(new EnormousStruct()); | ||
|
||
private void AddToList<T>(T item) | ||
{ | ||
var count = SegmentCount * SegmentedArrayHelper.GetSegmentSize<T>(); | ||
if (AddExtraItem) | ||
count++; | ||
|
||
var array = new SegmentedList<T>(); | ||
for (var i = 0; i < count; i++) | ||
array.Add(item); | ||
} | ||
|
||
private struct MediumStruct | ||
{ | ||
public int i1 { get; set; } | ||
public int i2 { get; set; } | ||
public int i3 { get; set; } | ||
public int i4 { get; set; } | ||
public int i5 { get; set; } | ||
} | ||
|
||
private struct LargeStruct | ||
{ | ||
public MediumStruct s1 { get; set; } | ||
public MediumStruct s2 { get; set; } | ||
public MediumStruct s3 { get; set; } | ||
public MediumStruct s4 { get; set; } | ||
} | ||
|
||
private struct EnormousStruct | ||
{ | ||
public LargeStruct s1 { get; set; } | ||
public LargeStruct s2 { get; set; } | ||
public LargeStruct s3 { get; set; } | ||
public LargeStruct s4 { get; set; } | ||
public LargeStruct s5 { get; set; } | ||
public LargeStruct s6 { get; set; } | ||
public LargeStruct s7 { get; set; } | ||
public LargeStruct s8 { get; set; } | ||
public LargeStruct s9 { get; set; } | ||
public LargeStruct s10 { get; set; } | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 I don't like this being on the general
Capacity.set
path, since it could penalize users who are setting a capacity specifically because they know the exact size of the resulting collection. It would be preferable to have this only occur on theGrow(int)
path.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense, let me move this to Grow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried to move this to Grow and not modify the Capacity setter, but it ended up needing to duplicate pretty much all the logic in the Capacity setter. So, I created a helper method that both places can call into that takes in a flag to specify whether the doubling is desired for the segment array.