Skip to content

Commit 9dc43ee

Browse files
authored
[Routing] Speed up ILEmitTrie jump table using Binary Search Tree (#52928)
* Uses binary search for 4 or more entries in a given table. * Matches input on length first. * Uses binary search when performing vectorized comparisons. * Uses binary search on single character comparisons and optimizes the code when all characters are letters.
1 parent 8e435d1 commit 9dc43ee

File tree

3 files changed

+300
-95
lines changed

3 files changed

+300
-95
lines changed

src/Http/Routing/perf/Microbenchmarks/Matching/JumpTableMultipleEntryBenchmark.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using BenchmarkDotNet.Attributes;
@@ -154,11 +154,20 @@ private static string[] GetStrings(int count)
154154

155155
// Between 5 and 36 characters
156156
var text = guid.Substring(0, Math.Max(5, Math.Min(i, 36)));
157-
if (char.IsDigit(text[0]))
157+
158+
// Convert first half of text to letters
159+
text = string.Create(text.Length, text, static (buffer, state) =>
158160
{
159-
// Convert first character to a letter.
160-
text = ((char)(text[0] + ('G' - '0'))) + text.Substring(1);
161-
}
161+
for (var c = 0; c < buffer.Length; c++)
162+
{
163+
buffer[c] = char.ToUpperInvariant(state[c]);
164+
165+
if (char.IsDigit(buffer[c]) && c < buffer.Length / 2)
166+
{
167+
buffer[c] = ((char)(state[c] + ('G' - '0')));
168+
}
169+
}
170+
});
162171

163172
if (i % 2 == 0)
164173
{

0 commit comments

Comments
 (0)