-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Implement new SmallCapacityDictionary for dictionaries with a small amount of values. #31360
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
Merged
Merged
Changes from 11 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
c87b685
Trying routevaluedict
jkotalik 485474b
New dictionary
jkotalik 51dccd2
Minor cleanup
jkotalik 5e0cdc9
Comparers
jkotalik 65d1055
Some benchmarks
jkotalik 183287f
Fixing for large capacity
jkotalik 8458629
Tests
jkotalik a4b53f5
Feedback
jkotalik 58558d7
nit
jkotalik c82a205
nit
jkotalik 2733b31
More build issues
jkotalik b7d7944
No struct for testing
jkotalik b29bbde
ordre
jkotalik e7e72e7
Fixing two tests
jkotalik 9690007
Fix check
jkotalik 6eb4375
Feedback
jkotalik 6cfeb8c
fixing test
jkotalik 11f8c43
remove comment
jkotalik 3da0a96
Feedback
jkotalik 1c7c005
Perf tests and new limit
jkotalik a139d9a
Update AdaptiveCapacityDictionaryTests.cs
jkotalik 4a95eea
Update AdaptiveCapacityDictionary.cs
jkotalik 069c519
Feedback
jkotalik 5342d4d
Add comment
jkotalik 7348343
Removing adaptive restriction
jkotalik 4456cc0
wrong check for capacity
jkotalik 58b5f09
Remove cast and add constructor
jkotalik 8768f0e
Nit
jkotalik 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 hidden or 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 hidden or 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
150 changes: 150 additions & 0 deletions
150
src/Http/Http/perf/Microbenchmarks/SmallCapacityDictionaryBenchmark.cs
This file contains hidden or 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,150 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using BenchmarkDotNet.Attributes; | ||
using Microsoft.AspNetCore.Internal.Dictionary; | ||
|
||
namespace Microsoft.AspNetCore.Http | ||
{ | ||
public class SmallCapacityDictionaryBenchmark | ||
{ | ||
private SmallCapacityDictionary<string, string> _smallCapDict; | ||
private SmallCapacityDictionary<string, string> _smallCapDictFour; | ||
private SmallCapacityDictionary<string, string> _smallCapDictTen; | ||
private Dictionary<string, string> _dict; | ||
private Dictionary<string, string> _dictFour; | ||
private Dictionary<string, string> _dictTen; | ||
|
||
private KeyValuePair<string, string> _oneValue; | ||
private List<KeyValuePair<string, string>> _fourValues; | ||
private List<KeyValuePair<string, string>> _tenValues; | ||
|
||
[IterationSetup] | ||
public void Setup() | ||
{ | ||
_oneValue = new KeyValuePair<string, string>("a", "b"); | ||
|
||
_fourValues = new List<KeyValuePair<string, string>>() | ||
{ | ||
new KeyValuePair<string, string>("a", "b"), | ||
new KeyValuePair<string, string>("c", "d"), | ||
new KeyValuePair<string, string>("e", "f"), | ||
new KeyValuePair<string, string>("g", "h"), | ||
}; | ||
|
||
_tenValues = new List<KeyValuePair<string, string>>() | ||
{ | ||
new KeyValuePair<string, string>("a", "b"), | ||
new KeyValuePair<string, string>("c", "d"), | ||
new KeyValuePair<string, string>("e", "f"), | ||
new KeyValuePair<string, string>("g", "h"), | ||
new KeyValuePair<string, string>("i", "j"), | ||
new KeyValuePair<string, string>("k", "l"), | ||
new KeyValuePair<string, string>("m", "n"), | ||
new KeyValuePair<string, string>("o", "p"), | ||
new KeyValuePair<string, string>("q", "r"), | ||
new KeyValuePair<string, string>("s", "t"), | ||
}; | ||
|
||
_smallCapDict = new SmallCapacityDictionary<string, string>(StringComparer.OrdinalIgnoreCase, capacity: 1); | ||
_smallCapDictFour = new SmallCapacityDictionary<string, string>(StringComparer.OrdinalIgnoreCase, capacity: 4); | ||
_smallCapDictTen = new SmallCapacityDictionary<string, string>(StringComparer.OrdinalIgnoreCase, capacity: 10); | ||
_dict = new Dictionary<string, string>(1, StringComparer.OrdinalIgnoreCase); | ||
_dictFour = new Dictionary<string, string>(4, StringComparer.OrdinalIgnoreCase); | ||
_dictTen = new Dictionary<string, string>(10, StringComparer.OrdinalIgnoreCase); | ||
} | ||
|
||
[Benchmark] | ||
public void OneValue_SmallDict() | ||
{ | ||
_smallCapDict[_oneValue.Key] = _oneValue.Value; | ||
_ = _smallCapDict[_oneValue.Key]; | ||
} | ||
|
||
[Benchmark] | ||
public void OneValue_Dict() | ||
{ | ||
_dict[_oneValue.Key] = _oneValue.Value; | ||
_ = _dict[_oneValue.Key]; | ||
} | ||
|
||
[Benchmark] | ||
public void FourValues_SmallDict() | ||
{ | ||
foreach (var val in _fourValues) | ||
{ | ||
_smallCapDictFour[val.Key] = val.Value; | ||
_ = _smallCapDictFour[val.Key]; | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void FourValues_Dict() | ||
{ | ||
foreach (var val in _fourValues) | ||
{ | ||
_dictFour[val.Key] = val.Value; | ||
_ = _dictFour[val.Key]; | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void TenValues_SmallDict() | ||
{ | ||
foreach (var val in _tenValues) | ||
{ | ||
_smallCapDictTen[val.Key] = val.Value; | ||
_ = _smallCapDictTen[val.Key]; | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void TenValues_Dict() | ||
{ | ||
foreach (var val in _tenValues) | ||
{ | ||
_dictTen[val.Key] = val.Value; | ||
_ = _dictTen[val.Key]; | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public void SmallDict() | ||
{ | ||
_ = new SmallCapacityDictionary<string, string>(capacity: 1); | ||
} | ||
|
||
[Benchmark] | ||
public void Dict() | ||
{ | ||
_ = new Dictionary<string, string>(capacity: 1); | ||
} | ||
|
||
|
||
[Benchmark] | ||
public void SmallDictFour() | ||
{ | ||
_ = new SmallCapacityDictionary<string, string>(capacity: 4); | ||
} | ||
|
||
[Benchmark] | ||
public void DictFour() | ||
{ | ||
_ = new Dictionary<string, string>(capacity: 4); | ||
} | ||
|
||
[Benchmark] | ||
public void SmallDictTen() | ||
{ | ||
_ = new SmallCapacityDictionary<string, string>(capacity: 10); | ||
} | ||
|
||
[Benchmark] | ||
public void DictTen() | ||
{ | ||
_ = new Dictionary<string, string>(capacity: 10); | ||
} | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.