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

Unified Diff: mojo/edk/system/channel.cc

Issue 1835933002: [mojo-edk] Trim read buffer to keep its size down (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/system/channel.cc
diff --git a/mojo/edk/system/channel.cc b/mojo/edk/system/channel.cc
index 67c739854d06e68704616344b55feea719ff5f72..ac666cf379099f318e93b3e859cfe958289cbfeb 100644
--- a/mojo/edk/system/channel.cc
+++ b/mojo/edk/system/channel.cc
@@ -34,7 +34,7 @@ static_assert(sizeof(Channel::Message::Header) == 8,
} // namespace
const size_t kReadBufferSize = 4096;
-const size_t kMaxUnusedReadBufferCapacity = 256 * 1024;
+const size_t kMaxUnusedReadBufferCapacity = 64 * 1024;
const size_t kMaxChannelMessageSize = 256 * 1024 * 1024;
const size_t kMaxAttachedHandles = 128;
@@ -408,8 +408,16 @@ class Channel::ReadBuffer {
num_occupied_bytes_ = num_preserved_bytes;
}
- // TODO: we should also adaptively shrink the buffer in case of the
- // occasional abnormally large read.
+ if (num_occupied_bytes_ == 0 && size_ > kMaxUnusedReadBufferCapacity) {
+ // Opportunistically shrink the read buffer back down to a small size if
+ // it's grown very large. We only do this if there are no remaining
+ // unconsumed bytes in the buffer to avoid copies in most the common
+ // cases.
+ size_ = kMaxUnusedReadBufferCapacity;
+ base::AlignedFree(data_);
+ data_ = static_cast<char*>(
+ base::AlignedAlloc(size_, kChannelMessageAlignment));
+ }
}
private:
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698