Commit eed268f9 authored by ncbray@chromium.org's avatar ncbray@chromium.org

Let RedirectToFileResourceHandler resize its internal buffer.

This can decrease NaCl's total warm load time by ~15% for larger files.
The algorithm for resizing the buffer matches the one used by
AsyncResourceHandler.

BUG= none
TEST= none


Review URL: https://chromiumcodereview.appspot.com/10828024

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148664 0039d316-1c4b-4281-b951-d872f2087c98
parent 77f86686
......@@ -23,8 +23,8 @@ using webkit_blob::ShareableFileReference;
namespace content {
// TODO(darin): Use the buffer sizing algorithm from AsyncResourceHandler.
static const int kReadBufSize = 32768;
static const int kInitialReadBufSize = 32768;
static const int kMaxReadBufSize = 524288;
RedirectToFileResourceHandler::RedirectToFileResourceHandler(
scoped_ptr<ResourceHandler> next_handler,
......@@ -39,6 +39,7 @@ RedirectToFileResourceHandler::RedirectToFileResourceHandler(
buf_write_pending_(false),
write_cursor_(0),
write_callback_pending_(false),
next_buffer_size_(kInitialReadBufSize),
did_defer_(false),
completed_during_write_(false) {
}
......@@ -92,8 +93,8 @@ bool RedirectToFileResourceHandler::OnWillRead(int request_id,
int min_size) {
DCHECK_EQ(-1, min_size);
if (!buf_->capacity())
buf_->SetCapacity(kReadBufSize);
if (buf_->capacity() < next_buffer_size_)
buf_->SetCapacity(next_buffer_size_);
// We should have paused this network request already if the buffer is full.
DCHECK(!BufIsFull());
......@@ -111,8 +112,14 @@ bool RedirectToFileResourceHandler::OnReadCompleted(int request_id,
DCHECK(buf_write_pending_);
buf_write_pending_ = false;
// We use the buffer's offset field to record the end of the buffer.
if (buf_->capacity() == bytes_read) {
// The network layer has saturated our buffer. Next time, we should give it
// a bigger buffer for it to fill, to minimize the number of round trips we
// do with the renderer process.
next_buffer_size_ = std::min(next_buffer_size_ * 2, kMaxReadBufSize);
}
// We use the buffer's offset field to record the end of the buffer.
int new_offset = buf_->offset() + bytes_read;
DCHECK(new_offset <= buf_->capacity());
buf_->set_offset(new_offset);
......
......@@ -82,6 +82,13 @@ class RedirectToFileResourceHandler : public LayeredResourceHandler {
scoped_ptr<net::FileStream> file_stream_;
bool write_callback_pending_;
// |next_buffer_size_| is the size of the buffer to be allocated on the next
// OnWillRead() call. We exponentially grow the size of the buffer allocated
// when our owner fills our buffers. On the first OnWillRead() call, we
// allocate a buffer of 32k and double it in OnReadCompleted() if the buffer
// was filled, up to a maximum size of 512k.
int next_buffer_size_;
// We create a ShareableFileReference that's deletable for the temp
// file created as a result of the download.
scoped_refptr<webkit_blob::ShareableFileReference> deletable_file_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment