Skip to content

Commit

Permalink
Use std::list instead of std::deque for all buffers/queues in streams (
Browse files Browse the repository at this point in the history
  • Loading branch information
jp4a50 authored Jan 2, 2025
1 parent d72aa60 commit e32af7a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/workerd/api/streams/compression.c++
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#include <workerd/io/features.h>

#include <deque>
#include <iterator>
#include <list>
#include <vector>

namespace workerd::api {
Expand Down Expand Up @@ -489,7 +489,9 @@ class CompressionStreamImpl: public kj::Refcounted,

kj::Canceler canceler;
LazyBuffer output;
std::deque<PendingRead> pendingReads;
// We use std::list to keep memory overhead low when there are many streams with no or few pending
// reads.
std::list<PendingRead> pendingReads;
};
} // namespace

Expand Down
6 changes: 4 additions & 2 deletions src/workerd/api/streams/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <workerd/io/io-context.h>
#include <workerd/io/observer.h>

#include <deque>
#include <list>

namespace workerd::api {

Expand Down Expand Up @@ -377,7 +377,9 @@ class WritableStreamInternalController: public WritableStreamController {
}
};

std::deque<WriteEvent> queue;
// We use std::list to keep memory overhead low when there are many streams with no or few pending
// events.
std::list<WriteEvent> queue;
};

// An implementation of ReadableStreamSource and WritableStreamSink which communicates read and
Expand Down
12 changes: 8 additions & 4 deletions src/workerd/api/streams/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <workerd/jsg/jsg.h>

#include <deque>
#include <list>
#include <set>

namespace workerd::api {
Expand Down Expand Up @@ -544,8 +544,10 @@ class ConsumerImpl final {
struct Closed {};
using Errored = jsg::Value;
struct Ready {
std::deque<kj::OneOf<QueueEntry, Close>> buffer;
std::deque<ReadRequest> readRequests;
// We use std::list to keep memory overhead low when there are many streams with no or few
// pending entries/reads.
std::list<kj::OneOf<QueueEntry, Close>> buffer;
std::list<ReadRequest> readRequests;
size_t queueTotalSize = 0;

inline kj::StringPtr jsgGetMemoryName() const;
Expand Down Expand Up @@ -863,7 +865,9 @@ class ByteQueue final {
};

struct State {
std::deque<kj::Own<ByobRequest>> pendingByobReadRequests;
// We use std::list to keep memory overhead low when there are many streams with no or few
// pending reads.
std::list<kj::Own<ByobRequest>> pendingByobReadRequests;

JSG_MEMORY_INFO(ByteQueue::State) {
for (auto& request: pendingByobReadRequests) {
Expand Down

0 comments on commit e32af7a

Please sign in to comment.