dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.41k stars 10k forks source link

"CreateEmptyBuilder" but a little more robust #50096

Open Leonardo-Ferreira opened 1 year ago

Leonardo-Ferreira commented 1 year ago

Background and Motivation

I have a lot of microservices running on .net and one thing is very certain: they use a lot more memory than CPU... their are host on AKS and this is the big picture of my MEMORY OPTIMIZED pools:

image

One could argue that yeah, Azure could launch a VM set for 1cpu 8gb ram, but meanwhile, if I want to drive costs down on the hosting, I need to save memory...

Reading that "CreateEmptyBuilder" launches a app at 8.5MB brings tears to my eyes, because YESSSSS my teams will be able to run really slim microservices but also SHIIIIIIIIIT they will screw-up so bad counting on things that are usually there but won't be, like model mapping...

Proposed API

I would like to propose the "CreateMinimalApiBuilder", with just enough to serve the API part of the "WeatherForecast" default template. Nothing else.

A alternative could be template where the builder is explicit and we could just delete/comment things out

davidfowl commented 1 year ago

We're not adding another method that is between slim and empty. We already have 3, I'd suggest at this point building your own factory method using CreateEmptyBuilder as a building block.

Tratcher commented 1 year ago

Note 8.5MB is the size on disk, not in memory.

Leonardo-Ferreira commented 1 year ago

@davidfowl I wasn't aware of the CreateSlimBuilder() but perhaps some official documentation on the lines of

//this is equivalent to WebApplication.CreateBuilder();
var builder = WebApplication.CreateEmptyBuilder();
builder.AddThis();
builder.AddThat();
builder.AddAnotherThing();
builder.AddDontYouForgetAboutMe();

this way devs don't need go spelunking on the GitHub for that...

amcasey commented 1 year ago

@Leonardo-Ferreira Which editor are you using? I'd expect completion to offer both when you dot into WebApplication, especially if you've started typing "Create". Normally, I'm all for adding more docs, but it feels a little excessive to cross-link a method so close-by.