- Revision
- 119671
- Author
- [email protected]
- Date
- 2012-06-06 20:39:35 -0700 (Wed, 06 Jun 2012)
Log Message
IndexedDB: Optimize single-key get()
https://bugs.webkit.org/show_bug.cgi?id=85288
Patch by Alec Flett <[email protected]> on 2012-06-06
Reviewed by Tony Chang.
No new tests, this is just an optimization.
After a recent refactoring, we started creating
an internal cursor with every call to get(). The
most common use of get() is with a single key,
so provide a fast-path to avoid creating the cursor.
* Modules/indexeddb/IDBIndexBackendImpl.cpp:
(WebCore::IDBIndexBackendImpl::getByRangeInternal):
* Modules/indexeddb/IDBKeyRange.h:
(WebCore::IDBKeyRange::isOnlyKey):
(IDBKeyRange):
* Modules/indexeddb/IDBObjectStoreBackendImpl.cpp:
(WebCore::IDBObjectStoreBackendImpl::getByRangeInternal):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (119670 => 119671)
--- trunk/Source/WebCore/ChangeLog 2012-06-07 03:39:08 UTC (rev 119670)
+++ trunk/Source/WebCore/ChangeLog 2012-06-07 03:39:35 UTC (rev 119671)
@@ -1,3 +1,25 @@
+2012-06-06 Alec Flett <[email protected]>
+
+ IndexedDB: Optimize single-key get()
+ https://bugs.webkit.org/show_bug.cgi?id=85288
+
+ Reviewed by Tony Chang.
+
+ No new tests, this is just an optimization.
+
+ After a recent refactoring, we started creating
+ an internal cursor with every call to get(). The
+ most common use of get() is with a single key,
+ so provide a fast-path to avoid creating the cursor.
+
+ * Modules/indexeddb/IDBIndexBackendImpl.cpp:
+ (WebCore::IDBIndexBackendImpl::getByRangeInternal):
+ * Modules/indexeddb/IDBKeyRange.h:
+ (WebCore::IDBKeyRange::isOnlyKey):
+ (IDBKeyRange):
+ * Modules/indexeddb/IDBObjectStoreBackendImpl.cpp:
+ (WebCore::IDBObjectStoreBackendImpl::getByRangeInternal):
+
2012-06-06 Shezan Baig <[email protected]>
Caret is not rendered in empty inline contenteditable elements
Modified: trunk/Source/WebCore/Modules/indexeddb/IDBIndexBackendImpl.cpp (119670 => 119671)
--- trunk/Source/WebCore/Modules/indexeddb/IDBIndexBackendImpl.cpp 2012-06-07 03:39:08 UTC (rev 119670)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBIndexBackendImpl.cpp 2012-06-07 03:39:35 UTC (rev 119671)
@@ -149,22 +149,27 @@
{
IDB_TRACE("IDBIndexBackendImpl::getInternal");
- RefPtr<IDBBackingStore::Cursor> backingStoreCursor =
- index->backingStore()->openIndexCursor(index->databaseId(), index->m_objectStoreBackend->id(), index->id(), keyRange.get(), IDBCursor::NEXT);
+ RefPtr<IDBKey> key;
- if (!backingStoreCursor) {
- callbacks->onSuccess(SerializedScriptValue::undefinedValue());
- return;
+ if (keyRange->isOnlyKey())
+ key = keyRange->lower();
+ else {
+ RefPtr<IDBBackingStore::Cursor> backingStoreCursor = index->backingStore()->openIndexCursor(index->databaseId(), index->m_objectStoreBackend->id(), index->id(), keyRange.get(), IDBCursor::NEXT);
+
+ if (!backingStoreCursor) {
+ callbacks->onSuccess(SerializedScriptValue::undefinedValue());
+ return;
+ }
+ key = backingStoreCursor->key();
+ backingStoreCursor->close();
}
- String value = index->backingStore()->getObjectViaIndex(index->databaseId(), index->m_objectStoreBackend->id(), index->id(), *backingStoreCursor->key());
+ String value = index->backingStore()->getObjectViaIndex(index->databaseId(), index->m_objectStoreBackend->id(), index->id(), *key);
if (value.isNull()) {
callbacks->onSuccess(SerializedScriptValue::undefinedValue());
- backingStoreCursor->close();
return;
}
callbacks->onSuccess(SerializedScriptValue::createFromWire(value));
- backingStoreCursor->close();
}
void IDBIndexBackendImpl::getKeyInternal(ScriptExecutionContext* context, PassRefPtr<IDBIndexBackendImpl> index, PassRefPtr<IDBKeyRange> keyRange, PassRefPtr<IDBCallbacks> callbacks)
Modified: trunk/Source/WebCore/Modules/indexeddb/IDBKeyRange.h (119670 => 119671)
--- trunk/Source/WebCore/Modules/indexeddb/IDBKeyRange.h 2012-06-07 03:39:08 UTC (rev 119670)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBKeyRange.h 2012-06-07 03:39:35 UTC (rev 119671)
@@ -83,6 +83,11 @@
}
static PassRefPtr<IDBKeyRange> bound(PassRefPtr<IDBKey> lower, PassRefPtr<IDBKey> upper, bool lowerOpen, bool upperOpen, ExceptionCode&);
+ bool isOnlyKey()
+ {
+ return m_lower == m_upper && m_lowerType == LowerBoundOpen && m_upperType == UpperBoundClosed;
+ }
+
private:
IDBKeyRange(PassRefPtr<IDBKey> lower, PassRefPtr<IDBKey> upper, LowerBoundType lowerType, UpperBoundType upperType);
Modified: trunk/Source/WebCore/Modules/indexeddb/IDBObjectStoreBackendImpl.cpp (119670 => 119671)
--- trunk/Source/WebCore/Modules/indexeddb/IDBObjectStoreBackendImpl.cpp 2012-06-07 03:39:08 UTC (rev 119670)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBObjectStoreBackendImpl.cpp 2012-06-07 03:39:35 UTC (rev 119671)
@@ -95,22 +95,27 @@
void IDBObjectStoreBackendImpl::getInternal(ScriptExecutionContext*, PassRefPtr<IDBObjectStoreBackendImpl> objectStore, PassRefPtr<IDBKeyRange> keyRange, PassRefPtr<IDBCallbacks> callbacks)
{
- IDB_TRACE("IDBObjectStoreBackendImpl::getInternal");
- RefPtr<IDBBackingStore::Cursor> backingStoreCursor = objectStore->backingStore()->openObjectStoreCursor(objectStore->databaseId(), objectStore->id(), keyRange.get(), IDBCursor::NEXT);
- if (!backingStoreCursor) {
- callbacks->onSuccess(SerializedScriptValue::undefinedValue());
- return;
+ IDB_TRACE("IDBObjectStoreBackendImpl::getByRangeInternal");
+ RefPtr<IDBKey> key;
+ if (keyRange->isOnlyKey())
+ key = keyRange->lower();
+ else {
+ RefPtr<IDBBackingStore::Cursor> backingStoreCursor = objectStore->backingStore()->openObjectStoreCursor(objectStore->databaseId(), objectStore->id(), keyRange.get(), IDBCursor::NEXT);
+ if (!backingStoreCursor) {
+ callbacks->onSuccess(SerializedScriptValue::undefinedValue());
+ return;
+ }
+ key = backingStoreCursor->key();
+ backingStoreCursor->close();
}
- String wireData = objectStore->backingStore()->getObjectStoreRecord(objectStore->databaseId(), objectStore->id(), *backingStoreCursor->key());
+ String wireData = objectStore->backingStore()->getObjectStoreRecord(objectStore->databaseId(), objectStore->id(), *key);
if (wireData.isNull()) {
callbacks->onSuccess(SerializedScriptValue::undefinedValue());
- backingStoreCursor->close();
return;
}
callbacks->onSuccess(SerializedScriptValue::createFromWire(wireData));
- backingStoreCursor->close();
}
static PassRefPtr<IDBKey> fetchKeyFromKeyPath(SerializedScriptValue* value, const IDBKeyPath& keyPath)