Skip to content

Commit

Permalink
IndexedDB: Implement SharedBuffer version of put() / onSuccess()
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=110398

Reviewed by Tony Chang.

Source/WebCore:

This avoids all unnecessary data copies within the context of
IndexedDB proper, and removes all references to
SerializedScriptValue from the IndexedDB "backend".

No new tests because this is just a refactor.

* bindings/v8/IDBBindingUtilities.cpp:
(WebCore::deserializeIDBValueBuffer): New version of deserializeIDBValue which takes SharedBuffer.

Source/WebKit/chromium:

Proxy new SharedBuffer calls to WebIDBCallbacks through
to the new SharedBuffer-based IDBCallbacks.

* public/WebIDBCursor.h:
* src/IDBCallbacksProxy.cpp:
(WebKit::IDBCallbacksProxy::onSuccess):
(WebKit::IDBCallbacksProxy::onSuccessWithPrefetch):
* src/IDBCallbacksProxy.h:
(IDBCallbacksProxy):
* src/WebIDBCallbacksImpl.cpp:
(WebKit::WebIDBCallbacksImpl::onSuccess):
* src/WebIDBCallbacksImpl.h:
(WebIDBCallbacksImpl):
* tests/IDBAbortOnCorruptTest.cpp:
(WebCore::MockIDBCallbacks::onSuccess):
(WebCore::MockIDBCallbacks::onSuccessWithPrefetch):
* tests/IDBDatabaseBackendTest.cpp:
* tests/IDBRequestTest.cpp:
(WebKit::TEST_F):


Canonical link: https://commits.webkit.org/128836@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@143694 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
alecf committed Feb 22, 2013
1 parent 30a8960 commit da61c1d
Show file tree
Hide file tree
Showing 24 changed files with 185 additions and 103 deletions.
16 changes: 16 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,19 @@
2013-02-21 Alec Flett <alecflett@chromium.org>

IndexedDB: Implement SharedBuffer version of put() / onSuccess()
https://bugs.webkit.org/show_bug.cgi?id=110398

Reviewed by Tony Chang.

This avoids all unnecessary data copies within the context of
IndexedDB proper, and removes all references to
SerializedScriptValue from the IndexedDB "backend".

No new tests because this is just a refactor.

* bindings/v8/IDBBindingUtilities.cpp:
(WebCore::deserializeIDBValueBuffer): New version of deserializeIDBValue which takes SharedBuffer.

2013-02-21 Sheriff Bot <webkit.review.bot@gmail.com>

Unreviewed, rolling out r143691.
Expand Down
29 changes: 15 additions & 14 deletions Source/WebCore/Modules/indexeddb/IDBBackingStore.cpp
Expand Up @@ -781,7 +781,7 @@ bool IDBBackingStore::deleteObjectStore(IDBBackingStore::Transaction* transactio
return true;
}

bool IDBBackingStore::getRecord(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, const IDBKey& key, Vector<uint8_t>& record)
bool IDBBackingStore::getRecord(IDBBackingStore::Transaction* transaction, int64_t databaseId, int64_t objectStoreId, const IDBKey& key, Vector<char>& record)
{
IDB_TRACE("IDBBackingStore::getRecord");
LevelDBTransaction* levelDBTransaction = IDBBackingStore::Transaction::levelDBTransactionFrom(transaction);
Expand Down Expand Up @@ -1407,7 +1407,7 @@ class ObjectStoreKeyCursorImpl : public IDBBackingStore::Cursor {
}

// IDBBackingStore::Cursor
virtual const Vector<uint8_t>& value() const { ASSERT_NOT_REACHED(); return *new Vector<uint8_t>(); }
virtual PassRefPtr<SharedBuffer> value() const { ASSERT_NOT_REACHED(); return 0; }
virtual bool loadCurrentRow();

private:
Expand Down Expand Up @@ -1462,7 +1462,7 @@ class ObjectStoreCursorImpl : public IDBBackingStore::Cursor {
}

// IDBBackingStore::Cursor
virtual const Vector<uint8_t>& value() const { return m_currentValue; }
virtual PassRefPtr<SharedBuffer> value() const { return m_currentValue; }
virtual bool loadCurrentRow();

private:
Expand All @@ -1477,7 +1477,7 @@ class ObjectStoreCursorImpl : public IDBBackingStore::Cursor {
{
}

Vector<uint8_t> m_currentValue;
RefPtr<SharedBuffer> m_currentValue;
};

bool ObjectStoreCursorImpl::loadCurrentRow()
Expand All @@ -1504,9 +1504,9 @@ bool ObjectStoreCursorImpl::loadCurrentRow()
// FIXME: This re-encodes what was just decoded; try and optimize.
m_recordIdentifier.reset(encodeIDBKey(*m_currentKey), version);

m_currentValue.clear();
m_currentValue.appendRange(valuePosition, static_cast<const char*>(m_iterator->value().end()));

Vector<char> value;
value.append(valuePosition, m_iterator->value().end() - valuePosition);
m_currentValue = SharedBuffer::adoptVector(value);
return true;
}

Expand All @@ -1523,7 +1523,7 @@ class IndexKeyCursorImpl : public IDBBackingStore::Cursor {
}

// IDBBackingStore::Cursor
virtual const Vector<uint8_t>& value() const { ASSERT_NOT_REACHED(); return *new Vector<uint8_t>(); }
virtual PassRefPtr<SharedBuffer> value() const { ASSERT_NOT_REACHED(); return 0; }
virtual PassRefPtr<IDBKey> primaryKey() const { return m_primaryKey; }
virtual const IDBBackingStore::RecordIdentifier& recordIdentifier() const { ASSERT_NOT_REACHED(); return m_recordIdentifier; }
virtual bool loadCurrentRow();
Expand Down Expand Up @@ -1608,7 +1608,7 @@ class IndexCursorImpl : public IDBBackingStore::Cursor {
}

// IDBBackingStore::Cursor
virtual const Vector<uint8_t>& value() const { return m_currentValue; }
virtual PassRefPtr<SharedBuffer> value() const { return m_currentValue; }
virtual PassRefPtr<IDBKey> primaryKey() const { return m_primaryKey; }
virtual const IDBBackingStore::RecordIdentifier& recordIdentifier() const { ASSERT_NOT_REACHED(); return m_recordIdentifier; }
bool loadCurrentRow();
Expand All @@ -1628,7 +1628,7 @@ class IndexCursorImpl : public IDBBackingStore::Cursor {
}

RefPtr<IDBKey> m_primaryKey;
Vector<uint8_t> m_currentValue;
RefPtr<SharedBuffer> m_currentValue;
Vector<char> m_primaryLevelDBKey;
};

Expand Down Expand Up @@ -1672,8 +1672,8 @@ bool IndexCursorImpl::loadCurrentRow()
}

int64_t objectStoreDataVersion;
const char* t = decodeVarInt(result.begin(), result.end(), objectStoreDataVersion);
if (!t) {
valuePosition = decodeVarInt(result.begin(), result.end(), objectStoreDataVersion);
if (!valuePosition) {
INTERNAL_READ_ERROR(LoadCurrentRow);
return false;
}
Expand All @@ -1683,8 +1683,9 @@ bool IndexCursorImpl::loadCurrentRow()
return false;
}

m_currentValue.clear();
m_currentValue.appendRange(t, static_cast<const char*>(result.end()));
Vector<char> value;
value.append(valuePosition, result.end() - valuePosition);
m_currentValue = SharedBuffer::adoptVector(value);
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/Modules/indexeddb/IDBBackingStore.h
Expand Up @@ -78,7 +78,7 @@ class IDBBackingStore : public RefCounted<IDBBackingStore> {
int64_t m_version;
};

virtual bool getRecord(IDBBackingStore::Transaction*, int64_t databaseId, int64_t objectStoreId, const IDBKey&, Vector<uint8_t>& record) WARN_UNUSED_RETURN;
virtual bool getRecord(IDBBackingStore::Transaction*, int64_t databaseId, int64_t objectStoreId, const IDBKey&, Vector<char>& record) WARN_UNUSED_RETURN;
virtual bool putRecord(IDBBackingStore::Transaction*, int64_t databaseId, int64_t objectStoreId, const IDBKey&, PassRefPtr<SharedBuffer> value, RecordIdentifier*) WARN_UNUSED_RETURN;
virtual void clearObjectStore(IDBBackingStore::Transaction*, int64_t databaseId, int64_t objectStoreId);
virtual void deleteRecord(IDBBackingStore::Transaction*, int64_t databaseId, int64_t objectStoreId, const RecordIdentifier&);
Expand Down Expand Up @@ -115,7 +115,7 @@ class IDBBackingStore : public RefCounted<IDBBackingStore> {

virtual PassRefPtr<Cursor> clone() = 0;
virtual PassRefPtr<IDBKey> primaryKey() const { return m_currentKey; }
virtual const Vector<uint8_t>& value() const = 0;
virtual PassRefPtr<SharedBuffer> value() const = 0;
virtual const RecordIdentifier& recordIdentifier() const { return m_recordIdentifier; }
virtual ~Cursor() { }
virtual bool loadCurrentRow() = 0;
Expand Down
12 changes: 6 additions & 6 deletions Source/WebCore/Modules/indexeddb/IDBCallbacks.h
Expand Up @@ -33,7 +33,7 @@
#include "IDBDatabaseError.h"
#include "IDBKey.h"
#include "IDBKeyPath.h"
#include "SerializedScriptValue.h"
#include "SharedBuffer.h"
#include <wtf/RefCounted.h>

#if ENABLE(INDEXED_DATABASE)
Expand All @@ -50,23 +50,23 @@ class IDBCallbacks : public RefCounted<IDBCallbacks> {
// From IDBFactory.webkitGetDatabaseNames()
virtual void onSuccess(PassRefPtr<DOMStringList>) = 0;
// From IDBObjectStore/IDBIndex.openCursor(), IDBIndex.openKeyCursor()
virtual void onSuccess(PassRefPtr<IDBCursorBackendInterface>, PassRefPtr<IDBKey>, PassRefPtr<IDBKey> primaryKey, PassRefPtr<SerializedScriptValue>) = 0;
virtual void onSuccess(PassRefPtr<IDBCursorBackendInterface>, PassRefPtr<IDBKey>, PassRefPtr<IDBKey> primaryKey, PassRefPtr<SharedBuffer>) = 0;
// From IDBObjectStore.add()/put(), IDBIndex.getKey()
virtual void onSuccess(PassRefPtr<IDBKey>) = 0;
// From IDBObjectStore/IDBIndex.get()/count(), and various methods that yield null/undefined.
virtual void onSuccess(PassRefPtr<SerializedScriptValue>) = 0;
virtual void onSuccess(PassRefPtr<SharedBuffer>) = 0;
// From IDBObjectStore/IDBIndex.get() (with key injection)
virtual void onSuccess(PassRefPtr<SerializedScriptValue>, PassRefPtr<IDBKey>, const IDBKeyPath&) = 0;
virtual void onSuccess(PassRefPtr<SharedBuffer>, PassRefPtr<IDBKey>, const IDBKeyPath&) = 0;
// From IDBObjectStore/IDBIndex.count()
virtual void onSuccess(int64_t value) = 0;

// From IDBFactor.deleteDatabase(), IDBObjectStore/IDBIndex.get(), IDBObjectStore.delete(), IDBObjectStore.clear()
virtual void onSuccess() = 0;

// From IDBCursor.advance()/continue()
virtual void onSuccess(PassRefPtr<IDBKey>, PassRefPtr<IDBKey> primaryKey, PassRefPtr<SerializedScriptValue>) = 0;
virtual void onSuccess(PassRefPtr<IDBKey>, PassRefPtr<IDBKey> primaryKey, PassRefPtr<SharedBuffer>) = 0;
// From IDBCursor.advance()/continue()
virtual void onSuccessWithPrefetch(const Vector<RefPtr<IDBKey> >& keys, const Vector<RefPtr<IDBKey> >& primaryKeys, const Vector<RefPtr<SerializedScriptValue> >& values) = 0;
virtual void onSuccessWithPrefetch(const Vector<RefPtr<IDBKey> >& keys, const Vector<RefPtr<IDBKey> >& primaryKeys, const Vector<RefPtr<SharedBuffer> >& values) = 0;
// From IDBFactory.open()/deleteDatabase()
virtual void onBlocked(int64_t existingVersion) { ASSERT_NOT_REACHED(); }
// From IDBFactory.open()
Expand Down
16 changes: 8 additions & 8 deletions Source/WebCore/Modules/indexeddb/IDBCursorBackendImpl.cpp
Expand Up @@ -37,7 +37,7 @@
#include "IDBRequest.h"
#include "IDBTracing.h"
#include "IDBTransactionBackendImpl.h"
#include "SerializedScriptValue.h"
#include "SharedBuffer.h"

namespace WebCore {

Expand Down Expand Up @@ -138,7 +138,7 @@ void IDBCursorBackendImpl::CursorAdvanceOperation::perform(IDBTransactionBackend
IDB_TRACE("CursorAdvanceOperation");
if (!m_cursor->m_cursor || !m_cursor->m_cursor->advance(m_count)) {
m_cursor->m_cursor = 0;
m_callbacks->onSuccess(static_cast<SerializedScriptValue*>(0));
m_callbacks->onSuccess(static_cast<SharedBuffer*>(0));
return;
}

Expand All @@ -150,7 +150,7 @@ void IDBCursorBackendImpl::CursorIterationOperation::perform(IDBTransactionBacke
IDB_TRACE("CursorIterationOperation");
if (!m_cursor->m_cursor || !m_cursor->m_cursor->continueFunction(m_key.get())) {
m_cursor->m_cursor = 0;
m_callbacks->onSuccess(static_cast<SerializedScriptValue*>(0));
m_callbacks->onSuccess(static_cast<SharedBuffer*>(0));
return;
}

Expand Down Expand Up @@ -178,7 +178,7 @@ void IDBCursorBackendImpl::CursorPrefetchIterationOperation::perform(IDBTransact

Vector<RefPtr<IDBKey> > foundKeys;
Vector<RefPtr<IDBKey> > foundPrimaryKeys;
Vector<RefPtr<SerializedScriptValue> > foundValues;
Vector<RefPtr<SharedBuffer> > foundValues;

if (m_cursor->m_cursor)
m_cursor->m_savedCursor = m_cursor->m_cursor->clone();
Expand All @@ -197,11 +197,11 @@ void IDBCursorBackendImpl::CursorPrefetchIterationOperation::perform(IDBTransact

switch (m_cursor->m_cursorType) {
case KeyOnly:
foundValues.append(SerializedScriptValue::create());
foundValues.append(SharedBuffer::create());
break;
case KeyAndValue:
sizeEstimate += m_cursor->m_cursor->value().size();
foundValues.append(SerializedScriptValue::createFromWireBytes(m_cursor->m_cursor->value()));
sizeEstimate += m_cursor->m_cursor->value()->size();
foundValues.append(m_cursor->m_cursor->value());
break;
default:
ASSERT_NOT_REACHED();
Expand All @@ -214,7 +214,7 @@ void IDBCursorBackendImpl::CursorPrefetchIterationOperation::perform(IDBTransact
}

if (!foundKeys.size()) {
m_callbacks->onSuccess(static_cast<SerializedScriptValue*>(0));
m_callbacks->onSuccess(static_cast<SharedBuffer*>(0));
return;
}

Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/Modules/indexeddb/IDBCursorBackendImpl.h
Expand Up @@ -33,7 +33,7 @@
#include "IDBCursor.h"
#include "IDBCursorBackendInterface.h"
#include "IDBTransactionBackendImpl.h"
#include "SerializedScriptValue.h"
#include "SharedBuffer.h"
#include <wtf/OwnPtr.h>
#include <wtf/PassOwnPtr.h>
#include <wtf/RefPtr.h>
Expand Down Expand Up @@ -65,7 +65,7 @@ class IDBCursorBackendImpl : public IDBCursorBackendInterface {

PassRefPtr<IDBKey> key() const { return m_cursor->key(); }
PassRefPtr<IDBKey> primaryKey() const { return m_cursor->primaryKey(); }
PassRefPtr<SerializedScriptValue> value() const { return (m_cursorType == KeyOnly) ? 0 : SerializedScriptValue::createFromWireBytes(m_cursor->value()); }
PassRefPtr<SharedBuffer> value() const { return (m_cursorType == KeyOnly) ? 0 : m_cursor->value(); }
void close();

private:
Expand Down
Expand Up @@ -37,7 +37,6 @@ class IDBAny;
class IDBCallbacks;
class IDBKey;
class IDBRequest;
class SerializedScriptValue;

typedef int ExceptionCode;

Expand Down
14 changes: 7 additions & 7 deletions Source/WebCore/Modules/indexeddb/IDBDatabaseBackendImpl.cpp
Expand Up @@ -723,7 +723,7 @@ void GetOperation::perform(IDBTransactionBackendImpl* transaction)
bool ok;
if (m_indexId == IDBIndexMetadata::InvalidId) {
// Object Store Retrieval Operation
Vector<uint8_t> value;
Vector<char> value;
ok = m_backingStore->getRecord(transaction->backingStoreTransaction(), m_databaseId, m_objectStoreId, *key, value);
if (!ok) {
m_callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UnknownError, "Internal error in getRecord."));
Expand All @@ -736,11 +736,11 @@ void GetOperation::perform(IDBTransactionBackendImpl* transaction)
}

if (m_autoIncrement && !m_keyPath.isNull()) {
m_callbacks->onSuccess(SerializedScriptValue::createFromWireBytes(value), key, m_keyPath);
m_callbacks->onSuccess(SharedBuffer::adoptVector(value), key, m_keyPath);
return;
}

m_callbacks->onSuccess(SerializedScriptValue::createFromWireBytes(value));
m_callbacks->onSuccess(SharedBuffer::adoptVector(value));
return;

}
Expand All @@ -762,7 +762,7 @@ void GetOperation::perform(IDBTransactionBackendImpl* transaction)
}

// Index Referenced Value Retrieval Operation
Vector<uint8_t> value;
Vector<char> value;
ok = m_backingStore->getRecord(transaction->backingStoreTransaction(), m_databaseId, m_objectStoreId, *primaryKey, value);
if (!ok) {
m_callbacks->onError(IDBDatabaseError::create(IDBDatabaseException::UnknownError, "Internal error in getRecord."));
Expand All @@ -774,10 +774,10 @@ void GetOperation::perform(IDBTransactionBackendImpl* transaction)
return;
}
if (m_autoIncrement && !m_keyPath.isNull()) {
m_callbacks->onSuccess(SerializedScriptValue::createFromWireBytes(value), primaryKey, m_keyPath);
m_callbacks->onSuccess(SharedBuffer::adoptVector(value), primaryKey, m_keyPath);
return;
}
m_callbacks->onSuccess(SerializedScriptValue::createFromWireBytes(value));
m_callbacks->onSuccess(SharedBuffer::adoptVector(value));
}

void IDBDatabaseBackendImpl::put(int64_t transactionId, int64_t objectStoreId, PassRefPtr<SharedBuffer> value, PassRefPtr<IDBKey> key, PutMode putMode, PassRefPtr<IDBCallbacks> callbacks, const Vector<int64_t>& indexIds, const Vector<IndexKeys>& indexKeys)
Expand Down Expand Up @@ -964,7 +964,7 @@ void OpenCursorOperation::perform(IDBTransactionBackendImpl* transaction)
}

if (!backingStoreCursor) {
m_callbacks->onSuccess(static_cast<SerializedScriptValue*>(0));
m_callbacks->onSuccess(static_cast<SharedBuffer*>(0));
return;
}

Expand Down

0 comments on commit da61c1d

Please sign in to comment.