Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CAP
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
CAP
Commits
92904176
Commit
92904176
authored
Apr 15, 2019
by
彭伟
Committed by
Lemon
Apr 15, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use ReadOnlySpan<char> Improve performance after .netcoreapp2.1 (#192)
parent
7016ef29
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
112 additions
and
5 deletions
+112
-5
SkyApm.Benchmark.csproj
benchmark/SkyApm.Benchmark/SkyApm.Benchmark.csproj
+1
-1
UniqueIdGenerate.cs
benchmark/SkyApm.Benchmark/UniqueIdGenerate.cs
+1
-1
UniqueIdParse.cs
benchmark/SkyApm.Benchmark/UniqueIdParse.cs
+14
-0
skyapm-dotnet.sln
skyapm-dotnet.sln
+8
-1
SkyApm.Core.csproj
src/SkyApm.Core/SkyApm.Core.csproj
+2
-1
UniqueIdParser.cs
src/SkyApm.Core/Tracing/UniqueIdParser.cs
+31
-1
SkyApm.Core.Tests.csproj
test/SkyApm.Core.Tests/SkyApm.Core.Tests.csproj
+17
-0
UniqueIdParserTest.cs
test/SkyApm.Core.Tests/UniqueIdParserTest.cs
+38
-0
No files found.
benchmark/SkyApm.Benchmark/SkyApm.Benchmark.csproj
View file @
92904176
...
...
@@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework
>netcoreapp2.1</TargetFramework
>
<TargetFramework
s>netcoreapp2.0;netcoreapp2.1</TargetFrameworks
>
</PropertyGroup>
<ItemGroup>
...
...
benchmark/SkyApm.Benchmark/UniqueId.cs
→
benchmark/SkyApm.Benchmark/UniqueId
Generate
.cs
View file @
92904176
...
...
@@ -3,7 +3,7 @@ using SkyApm.Tracing;
namespace
SkyApm.Benchmark
{
public
class
UniqueId
public
class
UniqueId
Generate
{
private
static
readonly
IUniqueIdGenerator
Generator
=
new
UniqueIdGenerator
(
new
RuntimeEnvironment
());
...
...
benchmark/SkyApm.Benchmark/UniqueIdParse.cs
0 → 100644
View file @
92904176
using
BenchmarkDotNet.Attributes
;
using
SkyApm.Tracing
;
namespace
SkyApm.Benchmark
{
public
class
UniqueIdParse
{
private
static
readonly
IUniqueIdParser
Parser
=
new
UniqueIdParser
();
private
static
readonly
string
Id
=
new
UniqueId
(
long
.
MaxValue
,
long
.
MaxValue
,
long
.
MaxValue
).
ToString
();
[
Benchmark
]
public
void
Parse
()
=>
Parser
.
TryParse
(
Id
,
out
_
);
}
}
skyapm-dotnet.sln
View file @
92904176
...
...
@@ -86,10 +86,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkyApm.Agent.GeneralHost",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkyApm.Sample.GeneralHost", "sample\SkyApm.Sample.GeneralHost\SkyApm.Sample.GeneralHost.csproj", "{477D705E-576B-46C8-8F1E-9A86EDAE9D86}"
EndProject
Project("{
FAE04EC0-301F-11D3-BF4B-00C04F79EFBC
}") = "SkyApm.Benchmark", "benchmark\SkyApm.Benchmark\SkyApm.Benchmark.csproj", "{33581FDE-ABAF-4C27-A40A-1A2743309399}"
Project("{
9A19103F-16F7-4668-BE54-9A1E7A4F7556
}") = "SkyApm.Benchmark", "benchmark\SkyApm.Benchmark\SkyApm.Benchmark.csproj", "{33581FDE-ABAF-4C27-A40A-1A2743309399}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmark", "benchmark", "{2B7F59E8-147F-4399-9804-E7EAEF2DCB22}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkyApm.Core.Tests", "test\SkyApm.Core.Tests\SkyApm.Core.Tests.csproj", "{5E654407-E22F-4696-A33F-C4B372F547BD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
...
...
@@ -196,6 +198,10 @@ Global
{33581FDE-ABAF-4C27-A40A-1A2743309399}.Debug|Any CPU.Build.0 = Debug|Any CPU
{33581FDE-ABAF-4C27-A40A-1A2743309399}.Release|Any CPU.ActiveCfg = Release|Any CPU
{33581FDE-ABAF-4C27-A40A-1A2743309399}.Release|Any CPU.Build.0 = Release|Any CPU
{5E654407-E22F-4696-A33F-C4B372F547BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5E654407-E22F-4696-A33F-C4B372F547BD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5E654407-E22F-4696-A33F-C4B372F547BD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5E654407-E22F-4696-A33F-C4B372F547BD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
...
...
@@ -234,6 +240,7 @@ Global
{4C1CF0E7-4CD3-4731-9A56-E033D5216D58} = {EF6194B2-9ACB-49B9-8049-DD6AFAEB0399}
{477D705E-576B-46C8-8F1E-9A86EDAE9D86} = {844CEACD-4C85-4B15-9E2B-892B01FDA4BB}
{33581FDE-ABAF-4C27-A40A-1A2743309399} = {2B7F59E8-147F-4399-9804-E7EAEF2DCB22}
{5E654407-E22F-4696-A33F-C4B372F547BD} = {613F0980-91ED-4064-8E8C-168582EF4AD7}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {94C0DA2C-CCCB-4314-93A2-9809B5DD0583}
...
...
src/SkyApm.Core/SkyApm.Core.csproj
View file @
92904176
...
...
@@ -9,7 +9,8 @@
<PackageReleaseNotes>
</PackageReleaseNotes>
<RootNamespace>SkyWalking</RootNamespace>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0;netcoreapp2.1</TargetFrameworks>
<DefineConstants Condition="'$(TargetFramework)' == 'netcoreapp2.1'">$(DefineConstants);SPAN</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AspectCore.Extensions.Reflection" Version="1.2.0" />
...
...
src/SkyApm.Core/Tracing/UniqueIdParser.cs
View file @
92904176
...
...
@@ -16,6 +16,8 @@
*
*/
using
System
;
namespace
SkyApm.Tracing
{
public
class
UniqueIdParser
:
IUniqueIdParser
...
...
@@ -23,14 +25,42 @@ namespace SkyApm.Tracing
public
bool
TryParse
(
string
text
,
out
UniqueId
uniqueId
)
{
uniqueId
=
default
(
UniqueId
);
if
(
text
==
null
)
return
false
;
if
(
string
.
IsNullOrEmpty
(
text
))
return
false
;
#if SPAN
var
id
=
text
.
AsSpan
();
var
index
=
FindIndex
(
id
);
if
(
index
<
1
)
return
false
;
var
id1
=
id
.
Slice
(
0
,
index
);
index
=
FindIndex
(
id
.
Slice
(
index
+
1
));
if
(
index
<
1
)
return
false
;
if
(!
long
.
TryParse
(
id1
,
out
var
part0
))
return
false
;
if
(!
long
.
TryParse
(
id
.
Slice
(
id1
.
Length
+
1
,
index
),
out
var
part1
))
return
false
;
if
(!
long
.
TryParse
(
id
.
Slice
(
id1
.
Length
+
index
+
2
),
out
var
part2
))
return
false
;
#else
var
parts
=
text
.
Split
(
"\\."
.
ToCharArray
(),
3
);
if
(
parts
.
Length
<
3
)
return
false
;
if
(!
long
.
TryParse
(
parts
[
0
],
out
var
part0
))
return
false
;
if
(!
long
.
TryParse
(
parts
[
1
],
out
var
part1
))
return
false
;
if
(!
long
.
TryParse
(
parts
[
2
],
out
var
part2
))
return
false
;
#endif
uniqueId
=
new
UniqueId
(
part0
,
part1
,
part2
);
return
true
;
}
#if SPAN
private
static
int
FindIndex
(
ReadOnlySpan
<
char
>
id
)
{
var
index
=
0
;
do
{
if
(
id
[
index
]
==
'\\'
||
id
[
index
]
==
'.'
)
return
index
;
}
while
(++
index
<
id
.
Length
);
return
-
1
;
}
#endif
}
}
test/SkyApm.Core.Tests/SkyApm.Core.Tests.csproj
0 → 100644
View file @
92904176
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp2.0;netcoreapp2.1</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<ProjectReference Include="..\..\src\SkyApm.Core\SkyApm.Core.csproj" />
</ItemGroup>
</Project>
test/SkyApm.Core.Tests/UniqueIdParserTest.cs
0 → 100644
View file @
92904176
using
SkyApm.Tracing
;
using
System
;
using
Xunit
;
namespace
SkyApm.Core.Tests
{
public
class
UniqueIdParserTest
{
private
static
readonly
IUniqueIdParser
Parser
=
new
UniqueIdParser
();
[
Theory
]
[
InlineData
(
null
,
false
)]
[
InlineData
(
""
,
false
)]
[
InlineData
(
"1"
,
false
)]
[
InlineData
(
"1.1"
,
false
)]
[
InlineData
(
"1.1."
,
false
)]
[
InlineData
(
"1.1.a"
,
false
)]
[
InlineData
(
"1.1.1.1"
,
false
)]
[
InlineData
(
"1\\1.-1"
,
true
)]
public
void
TryParse_Return
(
string
text
,
bool
result
)
=>
Assert
.
Equal
(
result
,
Parser
.
TryParse
(
text
,
out
_
));
[
Theory
]
[
InlineData
(
"1.2.3"
,
1
,
2
,
3
)]
[
InlineData
(
"123.456.789"
,
123
,
456
,
789
)]
[
InlineData
(
"-1.-2.-3"
,
-
1
,
-
2
,
-
3
)]
[
InlineData
(
"9223372036854775807.9223372036854775807.9223372036854775807"
,
9223372036854775807
,
9223372036854775807
,
9223372036854775807
)]
[
InlineData
(
"-9223372036854775807.-9223372036854775807.-9223372036854775807"
,
-
9223372036854775807
,
-
9223372036854775807
,
-
9223372036854775807
)]
public
void
TryParse_Out
(
string
text
,
long
part1
,
long
part2
,
long
part3
)
{
Parser
.
TryParse
(
text
,
out
var
id
);
Assert
.
Equal
(
part1
,
id
.
Part1
);
Assert
.
Equal
(
part2
,
id
.
Part2
);
Assert
.
Equal
(
part3
,
id
.
Part3
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment