dotnet / dotnet/aspnetcore

Improve routing performance with constant stackalloc when matching

Open
#32,569 4 comments 0 reactions 0 assignees View on GitHub
area-mvc feature-routing Perf task
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

A possible place to improve matching performance is using a constant stackalloc:

https://github.com/dotnet/aspnetcore/blob/2783b1a700b5b7fb1652354fceb0ec7de0c1c73f/src/Http/Routing/src/Matching/DfaMatcher.cs#L45-L48

At the moment the maximum required size is calculated. Could use a constant size up to a limit (64?), and then switch to allocating array or array pool.

Verify any changes with performance tests.

Contributor guide

Open the contributing guide

Research direction

Start in src/Http/Routing/src/Matching/DfaMatcher.cs at lines 45-48 to understand the current maximum-size calculation. Then locate the routing performance tests and compare matching performance for a constant stackalloc limit and the fallback allocation path. Done means the change is implemented and its performance impact is verified by those tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend, performance
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.