Commit c1582e69 authored by Chris Mumford's avatar Chris Mumford Committed by Commit Bot

Fix memory performance regression in file:///*.svgz filter.

A speculative fix for a 7%-19.2% regression of memory use. This
change releases the ZLib buffers used for Gzip inflation - releasing
the memory as soon as it is no longer needed instead of waiting for
the URLResponseBodyConsumer instance to be deleted.

This change also fixes an incorrect reset of |zlib_wrapper_|, which
was calling release() instead of reset(), when zlib would fail to
initialize. This was likely a latent bug and not the cause of
the regression.

Bug: 901891
Change-Id: I52687f5614b7a76c52f4b9d5317deb33a299e4cb
Reviewed-on: https://chromium-review.googlesource.com/c/1317922Reviewed-by: default avatarYutaka Hirano <yhirano@chromium.org>
Commit-Queue: Chris Mumford <cmumford@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607124}
parent 809d8fb0
......@@ -4,6 +4,8 @@
#include "content/renderer/loader/url_response_body_consumer.h"
#include <algorithm>
#include "base/auto_reset.h"
#include "base/bind.h"
#include "base/macros.h"
......@@ -84,10 +86,9 @@ URLResponseBodyConsumer::URLResponseBodyConsumer(
: nullptr),
has_seen_end_of_data_(!handle_.is_valid()) {
if (zlib_wrapper_ && !zlib_wrapper_->Init()) {
// If zlib can't be initialized then release the wrapper which will result
// If zlib can't be initialized then reset the wrapper which will result
// in the compressed response being received and unable to be processed.
zlib_wrapper_.release();
inflate_buffer_.reset();
ReleaseZlibWrapper();
}
handle_watcher_.Watch(
handle_.get(), MOJO_HANDLE_SIGNAL_READABLE,
......@@ -100,14 +101,21 @@ void URLResponseBodyConsumer::OnComplete(
const network::URLLoaderCompletionStatus& status) {
if (has_been_cancelled_)
return;
ReleaseZlibWrapper();
has_received_completion_ = true;
status_ = status;
NotifyCompletionIfAppropriate();
}
void URLResponseBodyConsumer::ReleaseZlibWrapper() {
zlib_wrapper_.reset();
inflate_buffer_.reset();
}
void URLResponseBodyConsumer::Cancel() {
has_been_cancelled_ = true;
handle_watcher_.Cancel();
ReleaseZlibWrapper();
}
void URLResponseBodyConsumer::SetDefersLoading() {
......@@ -222,6 +230,7 @@ void URLResponseBodyConsumer::OnReadable(MojoResult unused) {
}
reclaim_accountant.reset();
}
ReleaseZlibWrapper();
}
void URLResponseBodyConsumer::NotifyCompletionIfAppropriate() {
......
......@@ -8,6 +8,7 @@
#include <stddef.h>
#include <stdint.h>
#include <memory>
#include <utility>
#include "base/macros.h"
......@@ -84,6 +85,8 @@ class CONTENT_EXPORT URLResponseBodyConsumer final
void NotifyCompletionIfAppropriate();
void ReleaseZlibWrapper();
const int request_id_;
ResourceDispatcher* resource_dispatcher_;
mojo::ScopedDataPipeConsumerHandle handle_;
......
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