dotnet / dotnet/aspnetcore

Consider reducing code duplication across core assemblies

Open
#46,915 7 comments 0 reactions 0 assignees View on GitHub
area-networking
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

Similar to https://github.com/dotnet/runtime/issues/36721, we should consider reducing code duplication for large chunks of code.

For example, the `StackTrace` code is currently compiled into 3 assemblies. 2 of these are used by default in the `dotnet new api` template. By combining this code into a single .dll, (see https://github.com/dotnet/aspnetcore/commit/bed28aada7ba9a03b2924d46bdf5dee2fc9b1b35), I was able to reduce the final app size by 30 KB.

before
9.66 MB (10,130,432 bytes)

after
9.63 MB (10,099,200 bytes)

From inspecting the mstat file, you can see that the Http.Extensions assembly got larger, but the Diagnostics and Hosting assemblies got smaller.

![image](https://user-images.githubusercontent.com/8291187/221686507-3dadc21c-e544-4d55-a9c9-d240a5905d89.png)

The drawback to this is we either need to:
* Make these APIs public
* Use InternalsVisibleTo

Using InternalsVisibleTo isn't that bad if the assemblies always ship together. If they ship in separate NuGet packages, which may version differently or get out-of-sync, this seems like a bad idea. For this instance though, the Diagnostics and Hosting assemblies only ship in the ASP.NET Core shared framework. So they version/update together.

cc @amcasey @halter73 @davidfowl

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.