Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use std::list instead of std::deque for all buffers/queues in streams #3260

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading