Skip to content

Commit

Permalink
Use std::list for WritableImpl::writeRequests.
Browse files Browse the repository at this point in the history
Previously we used std::deque but this has a large memory footprint when
empty in practice. Using std::list optimizes memory for the common case
of a lot of WritableStreams with empty queues.
  • Loading branch information
jp4a50 committed Dec 6, 2024
1 parent 60115fd commit 9867fe2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/workerd/api/streams/standard.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <workerd/jsg/jsg.h>
#include <workerd/util/weak-refs.h>

#include <list>

namespace workerd::api {

// =======================================================================================
Expand Down Expand Up @@ -367,7 +369,9 @@ class WritableImpl {
bool backpressure = false;
size_t highWaterMark = 1;

std::deque<WriteRequest> writeRequests;
// `writeRequests` is often going to be empty in common usage patterns, in which case std::list
// is more memory efficient than a std::deque, for example.
std::list<WriteRequest> writeRequests;
size_t amountBuffered = 0;
bool warnAboutExcessiveBackpressure = true;
size_t excessiveBackpressureWarningCount = 0;
Expand Down

0 comments on commit 9867fe2

Please sign in to comment.