Skip to content

Commit edd0f2c

Browse files
committed
Misc updates
1 parent 63fe351 commit edd0f2c

File tree

9 files changed

+455
-69
lines changed

9 files changed

+455
-69
lines changed

Elasticsearch.sln

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests.Domain", "tests\Tests
2323
EndProject
2424
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmarks", "benchmarks", "{B7B8819B-3197-4AB6-B61B-9E1BFD1EC302}"
2525
EndProject
26-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Benchmarks", "benchmarks\Benchmarks\Benchmarks.csproj", "{701DB05B-1F1B-485F-9EDF-0274EED4FF9F}"
26+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Benchmarks", "benchmarks\Benchmarks\Benchmarks.csproj", "{701DB05B-1F1B-485F-9EDF-0274EED4FF9F}"
27+
EndProject
28+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlaygroundV7x", "src\PlaygroundV7x\PlaygroundV7x.csproj", "{7141AB85-10C5-42AE-8FC7-B14A4216A89F}"
29+
EndProject
30+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Profiling", "benchmarks\Profiling\Profiling.csproj", "{5222D7CD-3663-49ED-98EA-4B5ECDF705BF}"
31+
EndProject
32+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D9FFF81B-26F3-4A26-9605-E3D22382E9A5}"
33+
ProjectSection(SolutionItems) = preProject
34+
global.json = global.json
35+
EndProjectSection
2736
EndProject
2837
Global
2938
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -131,6 +140,30 @@ Global
131140
{701DB05B-1F1B-485F-9EDF-0274EED4FF9F}.Release|x64.Build.0 = Release|Any CPU
132141
{701DB05B-1F1B-485F-9EDF-0274EED4FF9F}.Release|x86.ActiveCfg = Release|Any CPU
133142
{701DB05B-1F1B-485F-9EDF-0274EED4FF9F}.Release|x86.Build.0 = Release|Any CPU
143+
{7141AB85-10C5-42AE-8FC7-B14A4216A89F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
144+
{7141AB85-10C5-42AE-8FC7-B14A4216A89F}.Debug|Any CPU.Build.0 = Debug|Any CPU
145+
{7141AB85-10C5-42AE-8FC7-B14A4216A89F}.Debug|x64.ActiveCfg = Debug|Any CPU
146+
{7141AB85-10C5-42AE-8FC7-B14A4216A89F}.Debug|x64.Build.0 = Debug|Any CPU
147+
{7141AB85-10C5-42AE-8FC7-B14A4216A89F}.Debug|x86.ActiveCfg = Debug|Any CPU
148+
{7141AB85-10C5-42AE-8FC7-B14A4216A89F}.Debug|x86.Build.0 = Debug|Any CPU
149+
{7141AB85-10C5-42AE-8FC7-B14A4216A89F}.Release|Any CPU.ActiveCfg = Release|Any CPU
150+
{7141AB85-10C5-42AE-8FC7-B14A4216A89F}.Release|Any CPU.Build.0 = Release|Any CPU
151+
{7141AB85-10C5-42AE-8FC7-B14A4216A89F}.Release|x64.ActiveCfg = Release|Any CPU
152+
{7141AB85-10C5-42AE-8FC7-B14A4216A89F}.Release|x64.Build.0 = Release|Any CPU
153+
{7141AB85-10C5-42AE-8FC7-B14A4216A89F}.Release|x86.ActiveCfg = Release|Any CPU
154+
{7141AB85-10C5-42AE-8FC7-B14A4216A89F}.Release|x86.Build.0 = Release|Any CPU
155+
{5222D7CD-3663-49ED-98EA-4B5ECDF705BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
156+
{5222D7CD-3663-49ED-98EA-4B5ECDF705BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
157+
{5222D7CD-3663-49ED-98EA-4B5ECDF705BF}.Debug|x64.ActiveCfg = Debug|Any CPU
158+
{5222D7CD-3663-49ED-98EA-4B5ECDF705BF}.Debug|x64.Build.0 = Debug|Any CPU
159+
{5222D7CD-3663-49ED-98EA-4B5ECDF705BF}.Debug|x86.ActiveCfg = Debug|Any CPU
160+
{5222D7CD-3663-49ED-98EA-4B5ECDF705BF}.Debug|x86.Build.0 = Debug|Any CPU
161+
{5222D7CD-3663-49ED-98EA-4B5ECDF705BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
162+
{5222D7CD-3663-49ED-98EA-4B5ECDF705BF}.Release|Any CPU.Build.0 = Release|Any CPU
163+
{5222D7CD-3663-49ED-98EA-4B5ECDF705BF}.Release|x64.ActiveCfg = Release|Any CPU
164+
{5222D7CD-3663-49ED-98EA-4B5ECDF705BF}.Release|x64.Build.0 = Release|Any CPU
165+
{5222D7CD-3663-49ED-98EA-4B5ECDF705BF}.Release|x86.ActiveCfg = Release|Any CPU
166+
{5222D7CD-3663-49ED-98EA-4B5ECDF705BF}.Release|x86.Build.0 = Release|Any CPU
134167
EndGlobalSection
135168
GlobalSection(SolutionProperties) = preSolution
136169
HideSolutionNode = FALSE
@@ -144,6 +177,8 @@ Global
144177
{587DE66B-6FAB-4722-9C53-2812BEFB6A44} = {362B2776-4B29-46AB-B237-56776B5372B6}
145178
{0B4DCA79-10CC-4CB8-95D3-A4EB8C98BE1C} = {362B2776-4B29-46AB-B237-56776B5372B6}
146179
{701DB05B-1F1B-485F-9EDF-0274EED4FF9F} = {B7B8819B-3197-4AB6-B61B-9E1BFD1EC302}
180+
{7141AB85-10C5-42AE-8FC7-B14A4216A89F} = {D455EC79-E1E0-4509-B297-0DA3AED8DFF7}
181+
{5222D7CD-3663-49ED-98EA-4B5ECDF705BF} = {B7B8819B-3197-4AB6-B61B-9E1BFD1EC302}
147182
EndGlobalSection
148183
GlobalSection(ExtensibilityGlobals) = postSolution
149184
SolutionGuid = {CE74F821-B001-4C69-A58D-CF81F8B0B632}

benchmarks/Benchmarks/Benchmarks.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net5.0</TargetFramework>
5+
<TargetFramework>net6.0</TargetFramework>
66
<Nullable>enable</Nullable>
77
</PropertyGroup>
88

benchmarks/Benchmarks/Program.cs

Lines changed: 116 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -11,70 +11,129 @@ internal class Program
1111
{
1212
private static void Main()
1313
{
14-
var thing = new IndicesGetString() { NameCount = 3 };
15-
thing.Setup();
16-
thing.NaiveStringCreate();
14+
//var thing = new IndicesGetString() { NameCount = 3 };
15+
//thing.Setup();
16+
//thing.NaiveStringCreate();
1717

18-
BenchmarkRunner.Run<IndicesGetString>();
18+
//BenchmarkRunner.Run<OneOrMany>();
1919
}
2020
}
2121

22-
[MemoryDiagnoser]
23-
public class IndicesGetString
24-
{
25-
private readonly List<IndexName> _indices = new();
22+
//[MemoryDiagnoser]
23+
//public class IndicesGetString
24+
//{
25+
// private readonly List<IndexName> _indices = new();
2626

27-
private string _output = string.Empty;
27+
// private string _output = string.Empty;
2828

29-
private readonly ElasticsearchClientSettings _settings = new();
29+
// private readonly ElasticsearchClientSettings _settings = new();
3030

31-
[Params(1,3)]
32-
public int NameCount { get; set; }
31+
// [Params(1,3)]
32+
// public int NameCount { get; set; }
3333

34-
[GlobalSetup]
35-
public void Setup()
36-
{
37-
for (var i = 0; i < NameCount; i++)
38-
{
39-
_indices.Add($"item{i}");
40-
}
41-
}
34+
// [GlobalSetup]
35+
// public void Setup()
36+
// {
37+
// for (var i = 0; i < NameCount; i++)
38+
// {
39+
// _indices.Add($"item{i}");
40+
// }
41+
// }
4242

43-
[Benchmark(Baseline = true)]
44-
public void StringJoin()
45-
{
46-
var indices = _indices.Select(i => i.GetString(_settings)).Distinct();
47-
_output = string.Join(',', indices);
48-
}
43+
// [Benchmark(Baseline = true)]
44+
// public void StringJoin()
45+
// {
46+
// var indices = _indices.Select(i => i.GetString(_settings)).Distinct();
47+
// _output = string.Join(',', indices);
48+
// }
4949

50-
[Benchmark]
51-
public void NaiveStringCreate()
52-
{
53-
// This implementation does ensure distinct values
54-
// Is that really an issue as it's unlikely and would still be a valid request
55-
56-
var length = 0;
57-
58-
var indices = _indices;
59-
for (var i = 0; i < indices.Count; i++)
60-
{
61-
length += _indices[i].Value.Length + 1;
62-
}
63-
64-
length = length == 0 ? 0 : length - 1;
65-
66-
_output = string.Create(length, indices, (span, state) =>
67-
{
68-
var written = 0;
69-
for (var i = 0; i < indices.Count; i++)
70-
{
71-
var value = state[i].Value.AsSpan();
72-
value.CopyTo(span[written..]);
73-
written += value.Length;
74-
75-
if (i != indices.Count - 1)
76-
span[written++] = ',';
77-
}
78-
});
79-
}
80-
}
50+
// [Benchmark]
51+
// public void NaiveStringCreate()
52+
// {
53+
// // This implementation doesn't ensure distinct values
54+
// // Is that really an issue as it's unlikely and would still be a valid request?
55+
56+
// // Issue: This doesn't call the Inferrer so is not a fair test since we'd
57+
58+
// var length = 0;
59+
60+
// var indices = _indices;
61+
// for (var i = 0; i < indices.Count; i++)
62+
// {
63+
// length += _indices[i].Value.Length + 1;
64+
// }
65+
66+
// length = length == 0 ? 0 : length - 1;
67+
68+
// _output = string.Create(length, indices, (span, state) =>
69+
// {
70+
// var written = 0;
71+
// for (var i = 0; i < indices.Count; i++)
72+
// {
73+
// var value = state[i].Value.AsSpan();
74+
// value.CopyTo(span[written..]);
75+
// written += value.Length;
76+
77+
// if (i != indices.Count - 1)
78+
// span[written++] = ',';
79+
// }
80+
// });
81+
// }
82+
//}
83+
84+
///// <summary>
85+
///// Investigate whether it's "more efficient" to use a one or many design for Indices.
86+
///// This avoids extra allocations in the case of a single item but is not so good for > 1 item.
87+
///// </summary>
88+
//[MemoryDiagnoser]
89+
//public class OneOrMany
90+
//{
91+
// private readonly List<IndexName> _indices = new();
92+
93+
// private Indices? _finalIndices = null;
94+
// private IndicesV2? _finalIndicesV2 = null;
95+
96+
// private readonly ElasticsearchClientSettings _settings = new();
97+
98+
// [Params(1, 3)]
99+
// public int NameCount { get; set; }
100+
101+
// [GlobalSetup]
102+
// public void Setup()
103+
// {
104+
// for (var i = 0; i < NameCount; i++)
105+
// {
106+
// _indices.Add($"item{i}");
107+
// }
108+
// }
109+
110+
// [Benchmark(Baseline = true)]
111+
// public void PureHashSet() => _finalIndices = new Indices(_indices);
112+
113+
// [Benchmark]
114+
// public void OneOrManyConcept()
115+
// {
116+
// if (_indices.Count == 1)
117+
// _finalIndicesV2 = new IndicesV2(_indices[0]);
118+
// else
119+
// _finalIndicesV2 = new IndicesV2(_indices);
120+
// }
121+
122+
// internal partial class IndicesV2
123+
// {
124+
// public static readonly IndicesV2 All = new("_all");
125+
126+
// private readonly HashSet<IndexName>? _indices;
127+
// private readonly IndexName? _index;
128+
129+
// internal IndicesV2(IndexName index) => _index = index;
130+
131+
// public IndicesV2(IEnumerable<IndexName> indices)
132+
// {
133+
// if (_indices is null)
134+
// _indices = new HashSet<IndexName>();
135+
136+
// _indices.UnionWith(indices);
137+
// }
138+
// }
139+
//}

benchmarks/Profiling/Profiling.csproj

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="JetBrains.Profiler.Api" Version="1.1.8" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<ProjectReference Include="..\..\src\Nest\Nest.csproj" />
15+
</ItemGroup>
16+
17+
</Project>

benchmarks/Profiling/Program.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using JetBrains.Profiler.Api;
2+
using Nest;
3+
using Nest.IndexManagement;
4+
5+
var req1 = new DeleteRequest("test");
6+
7+
//var list = new List<IndexName>();
8+
//IEnumerable<IndexName> items = new IndexName[] { "a", "b" };
9+
10+
MemoryProfiler.ForceGc();
11+
12+
MemoryProfiler.CollectAllocations(true);
13+
14+
MemoryProfiler.GetSnapshot();
15+
16+
//var req = new DeleteRequest("test");
17+
18+
//var i = Indices.Parse("test");
19+
20+
var i = Indices.Single("test");
21+
22+
MemoryProfiler.GetSnapshot();
23+
24+
//if (req.AllowNoIndices.HasValue)
25+
//{
26+
27+
//}
28+
29+
_ = i.ToString();
30+
31+
MemoryProfiler.CollectAllocations(false);
32+
33+
//var source = new IndexName[] { "index-01", "index-02" };
34+
35+
//var indices = new Indices(source);
36+
//var indicesList = new IndicesList(source);
37+
38+
//MemoryProfiler.CollectAllocations(true);
39+
40+
//MemoryProfiler.GetSnapshot();
41+
42+
//var indices2 = new Indices(source);
43+
44+
//MemoryProfiler.GetSnapshot();
45+
46+
//var indicesList2 = new IndicesList(source);
47+
48+
//MemoryProfiler.GetSnapshot();
49+
50+
//MemoryProfiler.CollectAllocations(false);
51+
52+
//// Ensure no GC between snapshots
53+
//_ = indices2.Values.Count;
54+
//_ = indicesList2.Values.Count;

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "5.0.100",
3+
"version": "6.0.100-preview.7.21379",
44
"rollForward": "latestFeature",
55
"allowPrerelease": false
66
},

0 commit comments

Comments
 (0)