mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-12 18:08:15 +02:00
The old implementation stored chunks in a Vector, which meant every discard() had to call Vector::remove(0, N) to drop the consumed chunks from the front, shifting every remaining chunk down. For a stream used as a back-pressure queue, draining it by discarding one chunk at a time was quadratic in the queued chunk count: in RequestServer that cost about a second of CPU per large response. Replace it with a singly-linked list of chunks (head, tail, head read offset, tail write offset) so push-back and pop-front are both O(1) and no shifting ever happens. Each chunk now holds its CHUNK_SIZE byte array inline rather than a separately-allocated ByteBuffer, which also halves the per-chunk allocations. Teardown unlinks iteratively to avoid recursive OwnPtr destructors on very long chains.
7.6 KiB
7.6 KiB