Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(434)

Unified Diff: net/quic/core/quic_stream_sequencer_buffer.cc

Issue 2328633004: lazy allocation and early release memory in QuicStreamSequencerBuffer. Protected by --quic_reduce_s… (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/quic/core/quic_stream_sequencer_buffer.h ('k') | net/quic/core/quic_stream_sequencer_buffer_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/core/quic_stream_sequencer_buffer.cc
diff --git a/net/quic/core/quic_stream_sequencer_buffer.cc b/net/quic/core/quic_stream_sequencer_buffer.cc
index 011a016d100b582b731563c0b0eba849b5dcf530..c839e0795720cb4dadc9f183a187a2a5b33b8bdd 100644
--- a/net/quic/core/quic_stream_sequencer_buffer.cc
+++ b/net/quic/core/quic_stream_sequencer_buffer.cc
@@ -47,7 +47,11 @@ QuicStreamSequencerBuffer::QuicStreamSequencerBuffer(size_t max_capacity_bytes)
blocks_count_(
ceil(static_cast<double>(max_capacity_bytes) / kBlockSizeBytes)),
total_bytes_read_(0),
- blocks_(blocks_count_) {
+ reduce_sequencer_buffer_memory_life_time_(
+ FLAGS_quic_reduce_sequencer_buffer_memory_life_time), // NOLINT
+ blocks_(reduce_sequencer_buffer_memory_life_time_
+ ? nullptr
+ : new BufferBlock*[blocks_count_]()) {
Clear();
}
@@ -56,9 +60,11 @@ QuicStreamSequencerBuffer::~QuicStreamSequencerBuffer() {
}
void QuicStreamSequencerBuffer::Clear() {
- for (size_t i = 0; i < blocks_count_; ++i) {
- if (blocks_[i] != nullptr) {
- RetireBlock(i);
+ if (!reduce_sequencer_buffer_memory_life_time_ || blocks_ != nullptr) {
+ for (size_t i = 0; i < blocks_count_; ++i) {
+ if (blocks_[i] != nullptr) {
+ RetireBlock(i);
+ }
}
}
num_bytes_buffered_ = 0;
@@ -169,6 +175,13 @@ QuicErrorCode QuicStreamSequencerBuffer::OnStreamData(
bytes_avail = total_bytes_read_ + max_buffer_capacity_bytes_ - offset;
}
+ if (reduce_sequencer_buffer_memory_life_time_ && blocks_ == nullptr) {
+ blocks_.reset(new BufferBlock*[blocks_count_]());
+ for (size_t i = 0; i < blocks_count_; ++i) {
+ blocks_[i] = nullptr;
+ }
+ }
+
if (blocks_[write_block_num] == nullptr) {
// TODO(danzh): Investigate if using a freelist would improve performance.
// Same as RetireBlock().
@@ -393,6 +406,15 @@ size_t QuicStreamSequencerBuffer::FlushBufferedFrames() {
return total_bytes_read_ - prev_total_bytes_read;
}
+void QuicStreamSequencerBuffer::ReleaseWholeBuffer() {
+ if (!reduce_sequencer_buffer_memory_life_time_) {
+ // Don't release buffer if flag is off.
+ return;
+ }
+ Clear();
+ blocks_.reset(nullptr);
+}
+
size_t QuicStreamSequencerBuffer::ReadableBytes() const {
return gaps_.front().begin_offset - total_bytes_read_;
}
« no previous file with comments | « net/quic/core/quic_stream_sequencer_buffer.h ('k') | net/quic/core/quic_stream_sequencer_buffer_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698