News for hackers. Stuff that matters.
Re:Improving Performance with HTTP Streaming by byroot on Thursday May 18, 2023 @12:31AM (#35984142)
I wonder why they didn't consider 103 Early Hints instead, as it solves the same problem in a much more elegant way, and doesn't require to re-architecture your application.
Re:Improving Performance with HTTP Streaming by memco on Thursday May 18, 2023 @01:55AM (#35984516)
Can you share more? How are they implemented and how do they help?
Re:Improving Performance with HTTP Streaming by byroot on Thursday May 18, 2023 @02:08AM (#35984577)
See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/103

As they mention in the article, the main goal of streaming your response is to deliver the <head> tag to the browser sooner, so that it can start downloading assets sooner.

However it has many downsides like explained in the article (can't change response code or headers once they are sent etc), which requires many hacks.

103 early hints allow to asynchronously send "provisional" headers, including `Link rel=preload` headers, which the browser can use to start downloading assets, but without restricting in any way the final response rendering.

That's basically the same goal than HTTP2 Server Push (which was deprecated), but much simpler to implement (works with HTTP/1), and allow the browser not to download resources it already have in cache.

Re:Improving Performance with HTTP Streaming by LinusU on Thursday May 18, 2023 @02:29AM (#35984681)
103 Early Hints is "experimental technology" (according to MDN) and isn't supported by Safari and Firefox. In Chrome it's only supported when using HTTP/2 or later (Firefox Nightly support it for HTTP/1).

ref: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/103

Re:Improving Performance with HTTP Streaming by vrnvu on Thursday May 18, 2023 @02:35AM (#35984717)
Simple solutions don't get software engineers promoted for their architecture skills, and catchy blog posts can't be written.
Re:Improving Performance with HTTP Streaming by dmw_ng on Thursday May 18, 2023 @03:03AM (#35984881)
Early hints solves a different problem, there you have a list of asset URLs you know your rendered page will need. This is about producing pieces of rendered page as computation completes on the backend.

Implementing this is a pain in the ass, any new intermediary (haproxy, nginx, ...) introduces a potential new source of buffering or IO loop that attempts to helpfully batch up your writes. But when the technique is implemented, it is legitimately an amazing way to reduce latency at the client.

I use this technique in an app where an opening chunk is used to ensure the browser has begun fetching/executing the app JS bundle before a list response is rendered. After the list is rendered (incrementally as each chunk becomes available) it is again used to execute a slow summary query without having to break out a separate request. All that fits in a single HTTP response body, no additional latency is introduced by making separate API requests for the list or for the counts. Because of the initial chunk causing the JS to execute, it is also possible for the app to display certain dialogs (depending on query string parameters) that are immediately ready for user input even before the subsequent responses have finished rendering or downloading. In the case of this specific app, the technique means some dialogs are usable 300ms earlier than otherwise

Another issue not touched on in the post is how all this newly unbuffered incrementally-arriving data interacts with visual rendering on the client, there is potential for a lot of flicker and burned CPU continually re-rendering UI elements.

It sounds like Airbnb are disabling compression to make their implementation work. So long as CPU isn't a problem, you can also implement compression in the backend, and flush the compressor each time some useful unit of work is produced (some task completes, or some amount of data e.g. aligned to the size of an Ethernet MTU is available for writing). Assuming all the stars align, this should produce compressed output in a form the browser can act on every time it manages to read any amount of data from the backend.

All this effort seems like nonsense until finding you have a perfectly functional app on a crappy airport wifi network where it was otherwise impossible to even get Google to load

Re:Improving Performance with HTTP Streaming by byroot on Thursday May 18, 2023 @03:23AM (#35984987)
> Early hints solves a different problem

I think it saves the same main problem which is to trigger assets download early.

However you are right streaming the response has a few extra advantages.

I still think getting most of the results with a tiny fraction of the effort is a better solution, but your mileage may vary.

Re:Improving Performance with HTTP Streaming by dmw_ng on Thursday May 18, 2023 @03:28AM (#35985003)
What if the assets are a list of URLs computed incrementally? In my app's case, the specific JS bundle variant to load is itself a result of a database query. It's easy to see many scenarios where the majority of assets (e.g. say photos) aren't known prior to building the response body
Re:Improving Performance with HTTP Streaming by byroot on Thursday May 18, 2023 @03:33AM (#35985027)
But you can emit as many 103 as you want. So you can start by sending the statically known assets, and then emit an extra 103 each time you are at the stage where the other assets are known.