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

Unified Diff: net/disk_cache/simple/simple_entry_impl.cc

Issue 2874833005: SimpleCache: read small files all at once. (Closed)
Patch Set: Rename + comment a method. Created 3 years, 5 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/disk_cache/simple/simple_entry_impl.h ('k') | net/disk_cache/simple/simple_synchronous_entry.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/disk_cache/simple/simple_entry_impl.cc
diff --git a/net/disk_cache/simple/simple_entry_impl.cc b/net/disk_cache/simple/simple_entry_impl.cc
index afc18852a30f360778f51326459102dec6d7be94..2938dc68481a94e4dbfe7ad28b2f3be9b8119ba2 100644
--- a/net/disk_cache/simple/simple_entry_impl.cc
+++ b/net/disk_cache/simple/simple_entry_impl.cc
@@ -545,7 +545,8 @@ size_t SimpleEntryImpl::EstimateMemoryUsage() const {
return sizeof(SimpleSynchronousEntry) +
base::trace_event::EstimateMemoryUsage(pending_operations_) +
base::trace_event::EstimateMemoryUsage(executing_operation_) +
- (stream_0_data_ ? stream_0_data_->capacity() : 0);
+ (stream_0_data_ ? stream_0_data_->capacity() : 0) +
+ (stream_1_prefetch_data_ ? stream_1_prefetch_data_->capacity() : 0);
}
SimpleEntryImpl::~SimpleEntryImpl() {
@@ -846,11 +847,15 @@ void SimpleEntryImpl::ReadDataInternal(int stream_index,
// Since stream 0 data is kept in memory, it is read immediately.
if (stream_index == 0) {
- int ret_value = ReadStream0Data(buf, offset, buf_len);
- if (!callback.is_null()) {
- base::ThreadTaskRunnerHandle::Get()->PostTask(
- FROM_HERE, base::Bind(callback, ret_value));
- }
+ ReadInMemoryStreamData(stream_0_data_.get(), offset, buf_len, buf,
+ callback);
+ return;
+ }
+
+ // Sometimes we can read in-ram prefetched stream 1 data immediately, too.
+ if (stream_index == 1 && stream_1_prefetch_data_) {
+ ReadInMemoryStreamData(stream_1_prefetch_data_.get(), offset, buf_len, buf,
pasko 2017/07/11 13:24:12 perhaps we could record how much time it takes to
Maks Orlovich 2017/07/11 14:34:06 It's a memcpy? Doesn't sound that interesting... T
pasko 2017/07/11 16:17:31 sorry, wrong pointer, I was asking whether we can
Maks Orlovich 2017/07/12 16:06:09 It's not really a separate event, since it replace
pasko 2017/07/18 13:46:30 lulz :) I was writing it without knowing that you
+ callback);
return;
}
@@ -945,6 +950,10 @@ void SimpleEntryImpl::WriteDataInternal(int stream_index,
if (!doomed_ && backend_.get())
backend_->index()->UseIfExists(entry_hash_);
+ // Any stream 1 write invalidates the prefetched data.
+ if (stream_index == 1)
+ stream_1_prefetch_data_ = nullptr;
+
AdvanceCrc(buf, offset, buf_len, stream_index);
// |entry_stat| needs to be initialized before modifying |data_size_|.
@@ -1149,6 +1158,15 @@ void SimpleEntryImpl::CreationOperationComplete(
crc32s_[0] = in_results->stream_0_crc32;
crc32s_end_offset_[0] = in_results->entry_stat.data_size(0);
}
+
+ if (in_results->stream_1_data.get()) {
pasko 2017/07/18 13:46:30 almost a copy of the block above, perhaps make str
Maks Orlovich 2017/07/28 17:27:35 Done.
+ stream_1_prefetch_data_ = in_results->stream_1_data;
+ // The crc was read in SimpleSynchronousEntry.
+ crc_check_state_[1] = CRC_CHECK_DONE;
+ crc32s_[1] = in_results->stream_1_crc32;
+ crc32s_end_offset_[1] = in_results->entry_stat.data_size(1);
+ }
+
// If this entry was opened by hash, key_ could still be empty. If so, update
// it with the key read from the synchronous entry.
if (key_.empty()) {
@@ -1444,19 +1462,27 @@ void SimpleEntryImpl::RecordWriteDependencyType(
type, WRITE_DEPENDENCY_TYPE_MAX);
}
-int SimpleEntryImpl::ReadStream0Data(net::IOBuffer* buf,
- int offset,
- int buf_len) {
+void SimpleEntryImpl::ReadInMemoryStreamData(
+ net::GrowableIOBuffer* in_buf,
+ int offset,
+ int buf_len,
+ net::IOBuffer* out_buf,
+ const CompletionCallback& callback) {
+ int rv;
if (buf_len < 0) {
RecordReadResult(cache_type_, READ_RESULT_SYNC_READ_FAILURE);
- return 0;
+ rv = 0;
+ } else {
+ memcpy(out_buf->data(), in_buf->data() + offset, buf_len);
+ UpdateDataFromEntryStat(SimpleEntryStat(base::Time::Now(), last_modified_,
+ data_size_, sparse_data_size_));
+ RecordReadResult(cache_type_, READ_RESULT_SUCCESS);
+ rv = buf_len;
+ }
+ if (!callback.is_null()) {
+ base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
+ base::Bind(callback, rv));
}
- memcpy(buf->data(), stream_0_data_->data() + offset, buf_len);
- UpdateDataFromEntryStat(
- SimpleEntryStat(base::Time::Now(), last_modified_, data_size_,
- sparse_data_size_));
- RecordReadResult(cache_type_, READ_RESULT_SUCCESS);
- return buf_len;
}
int SimpleEntryImpl::SetStream0Data(net::IOBuffer* buf,
« no previous file with comments | « net/disk_cache/simple/simple_entry_impl.h ('k') | net/disk_cache/simple/simple_synchronous_entry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698