Skip to content

Commit

Permalink
Use string create if net6.0 or greater (#4183)
Browse files Browse the repository at this point in the history
* Use string create if net6.0 or greater

* run benchmarks on net6.0

* Revert some changes

* revert

* Fix BenchmarkComparer

* Ensure both data set exists for comparison.
  • Loading branch information
tonyredondo committed Jun 20, 2023
1 parent 477702e commit 89ce11d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
22 changes: 19 additions & 3 deletions tracer/build/_build/BenchmarkComparison/BenchmarkComparer.cs
Expand Up @@ -57,9 +57,14 @@ public static class BenchmarkComparer
{
var baseBenchmark = GetValueOrDefault(baseBenchmarksByName, id);
var diffBenchmark = GetValueOrDefault(diffBenchmarksByName, id);
if (baseBenchmark is null || diffBenchmark is null)
{
return default;
}
return (Id: id, Base: baseBenchmark, Diff: diffBenchmark);
})
.Where(i => i.Id is not null)
.ToList();
var benchmarkComparisons = matchedBenchmarks
.Select(x => new BenchmarkComparison(x.Id, x.Base, x.Diff, EquivalenceTestConclusion.Unknown))
Expand All @@ -75,9 +80,20 @@ public static class BenchmarkComparer
})
.ToList();

static string GetName(Benchmark benchmark) => benchmark.DisplayInfo.Contains("Toolchain=net472")
? $"{benchmark.FullName}-net472"
: $"{benchmark.FullName}-netcoreapp3.1";
static string GetName(Benchmark benchmark)
{
if (benchmark.DisplayInfo.Contains("Toolchain=net472"))
{
return $"{benchmark.FullName}-net472";
}

if (benchmark.DisplayInfo.Contains("Toolchain=net6.0"))
{
return $"{benchmark.FullName}-net6.0";
}

return $"{benchmark.FullName}-netcoreapp3.1";
}

static T GetValueOrDefault<T>(Dictionary<string, T> dict, string key)
=> dict.TryGetValue(key, out var value) ? value : default;
Expand Down
2 changes: 1 addition & 1 deletion tracer/build/_build/Build.cs
Expand Up @@ -416,7 +416,7 @@ void DeleteReparsePoints(string path)
var (framework, runtimes) = IsOsx switch
{
true => (TargetFramework.NETCOREAPP3_1, "net6.0"),
false => (TargetFramework.NET6_0, "net472 netcoreapp3.1"),
false => (TargetFramework.NET6_0, "net472 netcoreapp3.1 net6.0"),
};
DotNetRun(s => s
Expand Down
Expand Up @@ -138,7 +138,11 @@ internal static string CreateHeader(SpanContext context)
var samplingPriority = context.TraceContext?.SamplingPriority ?? context.SamplingPriority;
var sampled = samplingPriority > 0 ? "1" : "0";

#if NET6_0_OR_GREATER
return string.Create(null, stackalloc char[128], $"{context.RawTraceId}-{context.RawSpanId}-{sampled}");
#else
return $"{context.RawTraceId}-{context.RawSpanId}-{sampled}";
#endif
}
}
}
Expand Up @@ -122,8 +122,11 @@ internal static string CreateTraceParentHeader(SpanContext context)
{
var samplingPriority = context.TraceContext?.SamplingPriority ?? context.SamplingPriority ?? SamplingPriorityValues.AutoKeep;
var sampled = samplingPriority > 0 ? "01" : "00";

#if NET6_0_OR_GREATER
return string.Create(null, stackalloc char[128], $"00-{context.RawTraceId}-{context.RawSpanId}-{sampled}");
#else
return $"00-{context.RawTraceId}-{context.RawSpanId}-{sampled}";
#endif
}

internal static string CreateTraceStateHeader(SpanContext context)
Expand Down
Expand Up @@ -90,7 +90,11 @@ public static void GetMessageHeaders(EventArgs? eventArgs, out IServiceRemotingR

public static string GetSpanName(string spanKind)
{
#if NET6_0_OR_GREATER
return string.Create(null, stackalloc char[128], $"{SpanNamePrefix}.{spanKind}");
#else
return $"{SpanNamePrefix}.{spanKind}";
#endif
}

public static Span CreateSpan(
Expand Down

0 comments on commit 89ce11d

Please sign in to comment.