Fixing up a few small issues

The instruction matcher was missing a few details, which made it faster
than it should have been. Right now I'm trying to keep the design of
these in sync. Once I fixed that it exposed a legitimate bug that was
blocking the github benchmark.
This commit is contained in:
Ryan Nowak 2018-06-15 18:03:16 -07:00
parent 00e99dbbb2
commit 5b8db03a57
4 changed files with 10 additions and 12 deletions

View File

@ -61,10 +61,6 @@ namespace Microsoft.AspNetCore.Routing.Matchers
for (var i = 0; i < SampleCount; i++) for (var i = 0; i < SampleCount; i++)
{ {
var sample = _samples[i]; var sample = _samples[i];
if (sample == 805)
{
GC.KeepAlive(5);
}
var httpContext = _requests[sample]; var httpContext = _requests[sample];
await _dfa.MatchAsync(httpContext, feature); await _dfa.MatchAsync(httpContext, feature);
Validate(httpContext, _endpoints[sample], feature.Endpoint); Validate(httpContext, _endpoints[sample], feature.Endpoint);

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // 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. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Attributes;

View File

@ -63,7 +63,7 @@ namespace Microsoft.AspNetCore.Routing.Matchers
} }
var i = 0; var i = 0;
Candidate match = default(Candidate); var candidates = new List<Candidate>();
while (i < state.Instructions.Length) while (i < state.Instructions.Length)
{ {
var instruction = state.Instructions[i]; var instruction = state.Instructions[i];
@ -73,7 +73,7 @@ namespace Microsoft.AspNetCore.Routing.Matchers
{ {
if (count == instruction.Depth) if (count == instruction.Depth)
{ {
match = state.Candidates[instruction.Payload]; candidates.Add(state.Candidates[instruction.Payload]);
} }
i++; i++;
break; break;
@ -92,10 +92,11 @@ namespace Microsoft.AspNetCore.Routing.Matchers
} }
} }
if (match.Endpoint != null) var matches = new List<(Endpoint, RouteValueDictionary)>();
for (i = 0; i < candidates.Count; i++)
{ {
var values = new RouteValueDictionary(); var values = new RouteValueDictionary();
var parameters = match.Parameters; var parameters = candidates[i].Parameters;
if (parameters != null) if (parameters != null)
{ {
for (var j = 0; j < parameters.Length; j++) for (var j = 0; j < parameters.Length; j++)
@ -113,13 +114,13 @@ namespace Microsoft.AspNetCore.Routing.Matchers
} }
} }
feature.Endpoint = match.Endpoint; matches.Add((candidates[i].Endpoint, values));
feature.Values = values;
notmatch:; notmatch:;
} }
feature.Endpoint = matches.Count == 0 ? null : matches[0].Item1;
feature.Values = matches.Count == 0 ? null : matches[0].Item2;
return Task.CompletedTask; return Task.CompletedTask;
} }

View File

@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Routing.Matchers
return comparison; return comparison;
} }
comparison = y.Precedence.CompareTo(x.Precedence); comparison = x.Precedence.CompareTo(y.Precedence);
if (comparison != 0) if (comparison != 0)
{ {
return comparison; return comparison;