dotnet / dotnet/aspnetcore

Reduce allocations in cookie value parsing

Open
#8,314 9 comments 5 reactions 0 assignees View on GitHub
affected-medium area-networking enhancement Perf severity-minor
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

In the March 5th ASP.NET Community Standup @davidfowl mentioned perf improvements made by the team and the great @benaadams in header handling. I wanted to share that while profiling one of our apps one main contributor to string allocations is the cookie value parsing. Those allocations are just after refreshing the page 3 or 4 times.

![image](https://user-images.githubusercontent.com/697377/54007145-6298e880-412e-11e9-88d5-5e3f64a63c48.png)

Our app has a lot of cookies, anywhere between 30 & 40 cookies. However, most of the cookies (80%) come from third party scripts like:

- Google Analytics: adds 4 cookies
- Adobe SiteCatalyst: adds 4 cookies
- Optimizely: adds 2 cookies
- Dynatrace: adds 4 cookies

The list goes on and on, but you get the idea. Our apps do not care about these cookies, we have no interest in accessing them. Even our own cookies are not access on each request. So the question is, would it be possible to make the cookie value parsing even more lazy and only parse the cookies we explicitly ask for (`Request.Cookies["SomeCookie"]`)?

This is a very common problem. Here are a few popular websites with the issue of third party scripts polluting the domain with cookies:

https://www.cnet.com:
![image](https://user-images.githubusercontent.com/697377/54007581-83623d80-4130-11e9-892f-44886810d3ea.png)

https://www.cnn.com
![image](https://user-images.githubusercontent.com/697377/54007661-dfc55d00-4130-11e9-9dda-88849b42a883.png)

https://www.espn.com
![image](https://user-images.githubusercontent.com/697377/54007703-097e8400-4131-11e9-9525-6086e56ccfd6.png)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.