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

Side by Side Diff: content/child/indexed_db/proxy_webidbcursor_impl.cc

Issue 104663007: IndexedDB: Optimize IDBCursor.advance() if it occurs within prefetched range (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added unit test Created 7 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/child/indexed_db/proxy_webidbcursor_impl.h" 5 #include "content/child/indexed_db/proxy_webidbcursor_impl.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "content/child/thread_safe_sender.h" 9 #include "content/child/thread_safe_sender.h"
10 #include "content/child/indexed_db/indexed_db_dispatcher.h" 10 #include "content/child/indexed_db/indexed_db_dispatcher.h"
(...skipping 30 matching lines...) Expand all
41 IndexedDBDispatcher* dispatcher = 41 IndexedDBDispatcher* dispatcher =
42 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); 42 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get());
43 dispatcher->CursorDestroyed(ipc_cursor_id_); 43 dispatcher->CursorDestroyed(ipc_cursor_id_);
44 } 44 }
45 45
46 void RendererWebIDBCursorImpl::advance(unsigned long count, 46 void RendererWebIDBCursorImpl::advance(unsigned long count,
47 WebIDBCallbacks* callbacks_ptr) { 47 WebIDBCallbacks* callbacks_ptr) {
48 IndexedDBDispatcher* dispatcher = 48 IndexedDBDispatcher* dispatcher =
49 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); 49 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get());
50 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr); 50 scoped_ptr<WebIDBCallbacks> callbacks(callbacks_ptr);
51 if (count <= prefetch_keys_.size()) {
52 CachedAdvance(count, callbacks.get());
53 return;
54 }
51 ResetPrefetchCache(); 55 ResetPrefetchCache();
52 dispatcher->RequestIDBCursorAdvance( 56 dispatcher->RequestIDBCursorAdvance(
53 count, callbacks.release(), ipc_cursor_id_); 57 count, callbacks.release(), ipc_cursor_id_);
54 } 58 }
55 59
56 void RendererWebIDBCursorImpl::continueFunction( 60 void RendererWebIDBCursorImpl::continueFunction(
57 const WebIDBKey& key, 61 const WebIDBKey& key,
58 WebIDBCallbacks* callbacks_ptr) { 62 WebIDBCallbacks* callbacks_ptr) {
59 continueFunction(key, WebIDBKey::createNull(), callbacks_ptr); 63 continueFunction(key, WebIDBKey::createNull(), callbacks_ptr);
60 } 64 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 102
99 dispatcher->RequestIDBCursorContinue(IndexedDBKeyBuilder::Build(key), 103 dispatcher->RequestIDBCursorContinue(IndexedDBKeyBuilder::Build(key),
100 IndexedDBKeyBuilder::Build(primary_key), 104 IndexedDBKeyBuilder::Build(primary_key),
101 callbacks.release(), 105 callbacks.release(),
102 ipc_cursor_id_); 106 ipc_cursor_id_);
103 } 107 }
104 108
105 void RendererWebIDBCursorImpl::postSuccessHandlerCallback() { 109 void RendererWebIDBCursorImpl::postSuccessHandlerCallback() {
106 pending_onsuccess_callbacks_--; 110 pending_onsuccess_callbacks_--;
107 111
108 // If the onsuccess callback called continue() on the cursor again, 112 // If the onsuccess callback called continue()/advance() on the cursor
109 // and that continue was served by the prefetch cache, then 113 // again, and that request was served by the prefetch cache, then
110 // pending_onsuccess_callbacks_ would be incremented. 114 // pending_onsuccess_callbacks_ would be incremented. If not, it means the
111 // If not, it means the callback did something else, or nothing at all, 115 // callback did something else, or nothing at all, in which case we need to
112 // in which case we need to reset the cache. 116 // reset the cache.
113 117
114 if (pending_onsuccess_callbacks_ == 0) 118 if (pending_onsuccess_callbacks_ == 0)
115 ResetPrefetchCache(); 119 ResetPrefetchCache();
116 } 120 }
117 121
118 void RendererWebIDBCursorImpl::SetPrefetchData( 122 void RendererWebIDBCursorImpl::SetPrefetchData(
119 const std::vector<IndexedDBKey>& keys, 123 const std::vector<IndexedDBKey>& keys,
120 const std::vector<IndexedDBKey>& primary_keys, 124 const std::vector<IndexedDBKey>& primary_keys,
121 const std::vector<WebData>& values) { 125 const std::vector<WebData>& values) {
122 prefetch_keys_.assign(keys.begin(), keys.end()); 126 prefetch_keys_.assign(keys.begin(), keys.end());
123 prefetch_primary_keys_.assign(primary_keys.begin(), primary_keys.end()); 127 prefetch_primary_keys_.assign(primary_keys.begin(), primary_keys.end());
124 prefetch_values_.assign(values.begin(), values.end()); 128 prefetch_values_.assign(values.begin(), values.end());
125 129
126 used_prefetches_ = 0; 130 used_prefetches_ = 0;
127 pending_onsuccess_callbacks_ = 0; 131 pending_onsuccess_callbacks_ = 0;
128 } 132 }
129 133
134 void RendererWebIDBCursorImpl::CachedAdvance(unsigned long count,
135 WebIDBCallbacks* callbacks) {
136 DCHECK_GE(prefetch_keys_.size(), count);
137 DCHECK_EQ(prefetch_primary_keys_.size(), prefetch_keys_.size());
138 DCHECK_EQ(prefetch_values_.size(), prefetch_keys_.size());
139
140 while (count > 1) {
jsbell 2013/12/12 00:18:44 If we think this will be common we could replace t
alecflett 2013/12/19 00:41:39 I'd do that in another patch under the umbrella of
141 prefetch_keys_.pop_front();
142 prefetch_primary_keys_.pop_front();
143 prefetch_values_.pop_front();
144 ++used_prefetches_;
145 --count;
146 }
147
148 CachedContinue(callbacks);
149 }
150
130 void RendererWebIDBCursorImpl::CachedContinue(WebIDBCallbacks* callbacks) { 151 void RendererWebIDBCursorImpl::CachedContinue(WebIDBCallbacks* callbacks) {
131 DCHECK_GT(prefetch_keys_.size(), 0ul); 152 DCHECK_GT(prefetch_keys_.size(), 0ul);
132 DCHECK(prefetch_primary_keys_.size() == prefetch_keys_.size()); 153 DCHECK_EQ(prefetch_primary_keys_.size(), prefetch_keys_.size());
133 DCHECK(prefetch_values_.size() == prefetch_keys_.size()); 154 DCHECK_EQ(prefetch_values_.size(), prefetch_keys_.size());
134 155
135 IndexedDBKey key = prefetch_keys_.front(); 156 IndexedDBKey key = prefetch_keys_.front();
136 IndexedDBKey primary_key = prefetch_primary_keys_.front(); 157 IndexedDBKey primary_key = prefetch_primary_keys_.front();
137 // this could be a real problem.. we need 2 CachedContinues
138 WebData value = prefetch_values_.front(); 158 WebData value = prefetch_values_.front();
139 159
140 prefetch_keys_.pop_front(); 160 prefetch_keys_.pop_front();
141 prefetch_primary_keys_.pop_front(); 161 prefetch_primary_keys_.pop_front();
142 prefetch_values_.pop_front(); 162 prefetch_values_.pop_front();
143 used_prefetches_++; 163 ++used_prefetches_;
144 164
145 pending_onsuccess_callbacks_++; 165 ++pending_onsuccess_callbacks_;
146 166
147 callbacks->onSuccess(WebIDBKeyBuilder::Build(key), 167 callbacks->onSuccess(WebIDBKeyBuilder::Build(key),
148 WebIDBKeyBuilder::Build(primary_key), value); 168 WebIDBKeyBuilder::Build(primary_key), value);
149 } 169 }
150 170
151 void RendererWebIDBCursorImpl::ResetPrefetchCache() { 171 void RendererWebIDBCursorImpl::ResetPrefetchCache() {
152 continue_count_ = 0; 172 continue_count_ = 0;
153 prefetch_amount_ = kMinPrefetchAmount; 173 prefetch_amount_ = kMinPrefetchAmount;
154 174
155 if (!prefetch_keys_.size()) { 175 if (!prefetch_keys_.size()) {
156 // No prefetch cache, so no need to reset the cursor in the back-end. 176 // No prefetch cache, so no need to reset the cursor in the back-end.
157 return; 177 return;
158 } 178 }
159 179
160 IndexedDBDispatcher* dispatcher = 180 IndexedDBDispatcher* dispatcher =
161 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get()); 181 IndexedDBDispatcher::ThreadSpecificInstance(thread_safe_sender_.get());
162 dispatcher->RequestIDBCursorPrefetchReset( 182 dispatcher->RequestIDBCursorPrefetchReset(
163 used_prefetches_, prefetch_keys_.size(), ipc_cursor_id_); 183 used_prefetches_, prefetch_keys_.size(), ipc_cursor_id_);
164 prefetch_keys_.clear(); 184 prefetch_keys_.clear();
165 prefetch_primary_keys_.clear(); 185 prefetch_primary_keys_.clear();
166 prefetch_values_.clear(); 186 prefetch_values_.clear();
167 187
168 pending_onsuccess_callbacks_ = 0; 188 pending_onsuccess_callbacks_ = 0;
169 } 189 }
170 190
171 } // namespace content 191 } // namespace content
OLDNEW
« no previous file with comments | « content/child/indexed_db/proxy_webidbcursor_impl.h ('k') | content/child/indexed_db/proxy_webidbcursor_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698