Enable Response Buffering by default in Umbraco v9 #11122
Replies: 2 comments 13 replies
-
OK, I'm coming around to have this enabled by default. That would make a better experience to those new to Umbraco or looking for a more flexible experience. I wonder if Umbraco could have a configuration of "mode" that would enable the things behind the scenes (like buffering or whatever else we find) that allows devs to use Umbraco like Matt indicates. Like a "strict" or "flexible" setting. By default it would be set to "flexible" which would enable buffering. Just an idea because it may be more friendly for devs to find and be aware of a mode or configuration than the "buffering" .NET configuration setting which is a bit hidden IMO and it could include more of these type of "gotcha" settings in the future. Thanks for listening :) |
Beta Was this translation helpful? Give feedback.
-
As we're talking about the API the browser uses to fetch the website I think we need to be super careful to make sure we understand the real-world performance implications before a decision is made. i.e. testing with sites with realistic frontend payloads and server-side code, across HTTP/1.1, HTTP/2 and... 🥁 HTTP/3! I suspect if there are performance considerations HTTP3 is where they would show up as that actually multiplexes the frames and sends them asynchronously. |
Beta Was this translation helpful? Give feedback.
-
This is really going to polarize people (I know it already has in the Discord channel) but I want to see if we can discuss enabling response buffering by default in Umbraco v9.
Background
I've recently been setting up Vendr in Umbraco v9, building out a site and getting things working when I hit upon a problem. Something that worked in v8 didn't work in v9 anymore and this ultimately boils down to calling a method in my view that performs a task and then attempts to write a cookie. In v8 (NF) this all works fine, but in v9 (NC) this threw an exception.
After some investigation this appears to stem from the fact that in .NET Core the response is now returned in chunks, with the headers thus being the first thin that gets sent down the line, meaning that when the view starts to render, the headers have already been sent and so can no longer be modified and so the code from the view errors. This differs to v8 (NF) where responses would be buffered by default and so nothing would be sent until the whole page is rendered and thus anything could be changed right up to the request being sent.
In my investigations I found there were 2 ways to solve this issue:
Microsoft.AspNetCore.Buffering
and addapp.UseResponseBuffering();
to theStartup.Configure
method to re-anable response buffering.After a lengthy discussion on Discord, even though option 1 is the better practice, I'm now wondering if we should go with option 2 and enable response buffering by default?
Chunking vs Buffering
Currently the default in v9 / .NET Core is for responses to be chunked and so a response is sent to the browser as quickly as possible. This has the advantage of creating a great Time to First Byte (TTFB) response and allows the browser to start loading client resources as quickly as possible. With buffering though, nothing reaches the browser until the whole page is sent down the line and so it can take pages that little bit longer to start loading those resources.
There is also the argument that streaming takes up less server resources than buffering which needs to load the whole page into memory before sending it down the line.
Why enable buffering?
Considering the above, why would we even consider enabling buffering by default if chunking is more optimal? Well, my answer to this is Developer Experience (DX), and specifically beginners and "implementors".
With chunking, whilst it offers the best performance, it comes with some side effects. Because some resources get sent before views start to render, it now starts to pose problems for those that write logic into views. Yea, I know, we shouldn't be writing logic in views, but some times you just need to do something fast, or you just want to learn how something works, and other times you just need something done now. Umbraco has long had a history of supporting these devs and I think it is worth continuing with this.
But should we really introduce a perf issue for the sake of some devs following bad practice? Well, the question really is "how significant is the perf difference?" and from some historic issue on this, it appears not massively dotnet/aspnetcore#3100
This is a pretty old issue though so I don't know how this stacks up today, but it really shouldn't be getting any worse than this.
In addition to this, there is already something logged for .NET 7 to improve this in some way (either bring back buffering, or better handling, it's not clear) dotnet/aspnetcore#27470
Proposition
My proposition then is that given there may be improvements coming, and it's clear there are side effects to chunking that require more developer centric knowledge to deal with (ie, moving code to controllers / components), could we enable response buffering by default such that people just starting with Umbraco get a simple and friendly dev experience but then expose a means of disabling buffering once they are at the best practices stage or if it's being worked on by a dev team that know how to manage the new approach and already follow those best practices.
There is an argument that we should maybe make it configurable to "enable buffering", but I personally think this would be a mistake as you are then requiring beginners to do this, before they can have a nice experience. I really think it would be much better for them to get the simple experience, and those in the know wanting to get maximum performance can then disable it and handle the side effects.
Well, there it is, now how do I mute this thread? 😂
Beta Was this translation helpful? Give feedback.
All reactions