Faster streaming HTML with batches and aggregates
In this article, the author explores the benefits of server-based streaming HTML for faster web applications. The process involves generating the next version of the HTML page on the server and transmitting it to connected clients at regular intervals, typically every X milliseconds. This method of rendering, known as immediate mode, streamlines the rendering process and reduces the computational burden on the client-side.
The author emphasizes the importance of batching updates to minimize computational overhead and prevent accidental quadratic time complexity. By introducing barriers between the writing and rendering processes, the system can efficiently manage resources and optimize performance. Each batch of updates can be processed independently, with separate threads handling writes and renders to minimize contention and optimize resource utilization.
Compression techniques, such as Brotli or Zstandard, are discussed for reducing the network overhead of transmitting HTML frames. The use of embedded databases, like SQLite, for projections further enhances performance by enabling quick querying of data. Despite the need to query the database on each tick, the author argues that the benefits of batching, compression, and efficient resource management outweigh these concerns.
The final bottleneck in the rendering process, as identified by the author, is HTML templating. To address this, the article introduces the concept of aggregates, which allow for automatic caching of rendering components. By wrapping components in a cache and keying their output by their function and arguments, the system can optimize rendering times and reduce redundant computations.
This approach enables efficient rendering of shared widgets and dynamic content without compromising the system's performance in worst-case scenarios.
Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.