Re: [whatwg/streams] [Question] questions about streaming-element-backpressure.js (#855)

1. The reason this is at the beginning of write() is that start() is called when the element is created, which may be a long time before data actually starts streaming. The algorithm works by measuring the time between displayed frames and comparing it to its target of 33ms. It then adjusts the number of characters it processes at a time to try to hit the target. startNewChunk() has the effect of resetting the timer, so if it was called a long time before the first write() the measurement of the first frame would be wrong. Is there a way I could make this clearer to someone reading the code? One way to avoid the delay on the first frame would be to make a first chunks a special case. I was trying to make the code as simple as possible, so it is not optimised.
2. Writing into an iframe allows us to use document.write() to use the browser's streaming parser. I adapted this from code written by Jake Archibald, who wrote more about the technique here: https://jakearchibald.com/2016/fun-hacks-faster-content/. Compared to appending to innerHTML it means that only the new chunks need to be parsed, rather than all the HTML needed to be re-parsed for every new chunk of data. The main reason for doing it this way is to get as close to streaming HTML parsing as is possible in current browsers, but I expect the performance is good too.

This is a good place to ask about the demos.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/issues/855#issuecomment-344177595

Received on Tuesday, 14 November 2017 08:11:16 UTC