Title: [275547] trunk/Source/WebCore
Revision
275547
Author
[email protected]
Date
2021-04-06 13:43:00 -0700 (Tue, 06 Apr 2021)

Log Message

Shrink some IndexedDB-related classes
https://bugs.webkit.org/show_bug.cgi?id=224221

Reviewed by Geoffrey Garen.

Shrink some enum classes, and re-order data members to optimize packing in
IDBRequest and IDBKeyRangeData.

A couple of data members of IDBRequest were made private with protected setters.

This shrinks IDBRequest from 496 bytes to 448 bytes, and IDBKeyRangeData from 96
to 72 bytes on x86_64.

* Modules/indexeddb/IDBKeyData.h:
* Modules/indexeddb/IDBKeyRangeData.cpp:
(WebCore::IDBKeyRangeData::IDBKeyRangeData):
* Modules/indexeddb/IDBKeyRangeData.h:
(WebCore::IDBKeyRangeData::IDBKeyRangeData):
* Modules/indexeddb/IDBObjectStore.h:
* Modules/indexeddb/IDBOpenDBRequest.cpp:
(WebCore::IDBOpenDBRequest::IDBOpenDBRequest):
(WebCore::IDBOpenDBRequest::versionChangeTransactionDidFinish):
(WebCore::IDBOpenDBRequest::onSuccess):
(WebCore::IDBOpenDBRequest::onUpgradeNeeded):
(WebCore::IDBOpenDBRequest::onDeleteDatabaseSuccess):
* Modules/indexeddb/IDBRequest.cpp:
(WebCore::IDBRequest::IDBRequest):
* Modules/indexeddb/IDBRequest.h:
(WebCore::IDBRequest::setReadyState):
(WebCore::IDBRequest::setShouldExposeTransactionToDOM):
* Modules/indexeddb/IndexedDB.h:
* Modules/indexeddb/client/IDBConnectionToServerDelegate.h:
* Modules/indexeddb/server/MemoryIndex.h:
* Modules/indexeddb/server/MemoryObjectStore.h:
* Modules/indexeddb/shared/IDBCursorInfo.h:
* Modules/indexeddb/shared/IDBGetAllRecordsData.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (275546 => 275547)


--- trunk/Source/WebCore/ChangeLog	2021-04-06 20:39:10 UTC (rev 275546)
+++ trunk/Source/WebCore/ChangeLog	2021-04-06 20:43:00 UTC (rev 275547)
@@ -1,3 +1,42 @@
+2021-04-06  Simon Fraser  <[email protected]>
+
+        Shrink some IndexedDB-related classes
+        https://bugs.webkit.org/show_bug.cgi?id=224221
+
+        Reviewed by Geoffrey Garen.
+
+        Shrink some enum classes, and re-order data members to optimize packing in 
+        IDBRequest and IDBKeyRangeData.
+
+        A couple of data members of IDBRequest were made private with protected setters.
+
+        This shrinks IDBRequest from 496 bytes to 448 bytes, and IDBKeyRangeData from 96
+        to 72 bytes on x86_64.
+
+        * Modules/indexeddb/IDBKeyData.h:
+        * Modules/indexeddb/IDBKeyRangeData.cpp:
+        (WebCore::IDBKeyRangeData::IDBKeyRangeData):
+        * Modules/indexeddb/IDBKeyRangeData.h:
+        (WebCore::IDBKeyRangeData::IDBKeyRangeData):
+        * Modules/indexeddb/IDBObjectStore.h:
+        * Modules/indexeddb/IDBOpenDBRequest.cpp:
+        (WebCore::IDBOpenDBRequest::IDBOpenDBRequest):
+        (WebCore::IDBOpenDBRequest::versionChangeTransactionDidFinish):
+        (WebCore::IDBOpenDBRequest::onSuccess):
+        (WebCore::IDBOpenDBRequest::onUpgradeNeeded):
+        (WebCore::IDBOpenDBRequest::onDeleteDatabaseSuccess):
+        * Modules/indexeddb/IDBRequest.cpp:
+        (WebCore::IDBRequest::IDBRequest):
+        * Modules/indexeddb/IDBRequest.h:
+        (WebCore::IDBRequest::setReadyState):
+        (WebCore::IDBRequest::setShouldExposeTransactionToDOM):
+        * Modules/indexeddb/IndexedDB.h:
+        * Modules/indexeddb/client/IDBConnectionToServerDelegate.h:
+        * Modules/indexeddb/server/MemoryIndex.h:
+        * Modules/indexeddb/server/MemoryObjectStore.h:
+        * Modules/indexeddb/shared/IDBCursorInfo.h:
+        * Modules/indexeddb/shared/IDBGetAllRecordsData.h:
+
 2021-04-06  Ryosuke Niwa  <[email protected]>
 
         Assert failure in isCloneInShadowTreeOfSVGUseElement

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBKeyData.h (275546 => 275547)


--- trunk/Source/WebCore/Modules/indexeddb/IDBKeyData.h	2021-04-06 20:39:10 UTC (rev 275546)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBKeyData.h	2021-04-06 20:43:00 UTC (rev 275547)
@@ -191,10 +191,10 @@
     static void isolatedCopy(const IDBKeyData& source, IDBKeyData& destination);
 
     IndexedDB::KeyType m_type;
-    Variant<Vector<IDBKeyData>, String, double, ThreadSafeDataBuffer> m_value;
-
     bool m_isNull { false };
     bool m_isDeletedValue { false };
+
+    Variant<Vector<IDBKeyData>, String, double, ThreadSafeDataBuffer> m_value;
 };
 
 struct IDBKeyDataHash {

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBKeyRangeData.cpp (275546 => 275547)


--- trunk/Source/WebCore/Modules/indexeddb/IDBKeyRangeData.cpp	2021-04-06 20:39:10 UTC (rev 275546)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBKeyRangeData.cpp	2021-04-06 20:43:00 UTC (rev 275547)
@@ -31,20 +31,16 @@
 namespace WebCore {
 
 IDBKeyRangeData::IDBKeyRangeData(IDBKey* key)
-    : isNull(!key)
-    , lowerKey(key)
+    : lowerKey(key)
     , upperKey(key)
-    , lowerOpen(false)
-    , upperOpen(false)
+    , isNull(!key)
 {
 }
 
 IDBKeyRangeData::IDBKeyRangeData(const IDBKeyData& keyData)
-    : isNull(keyData.isNull())
-    , lowerKey(keyData)
+    : lowerKey(keyData)
     , upperKey(keyData)
-    , lowerOpen(false)
-    , upperOpen(false)
+    , isNull(keyData.isNull())
 {
 }
 

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBKeyRangeData.h (275546 => 275547)


--- trunk/Source/WebCore/Modules/indexeddb/IDBKeyRangeData.h	2021-04-06 20:39:10 UTC (rev 275546)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBKeyRangeData.h	2021-04-06 20:43:00 UTC (rev 275547)
@@ -35,8 +35,6 @@
 struct IDBKeyRangeData {
     IDBKeyRangeData()
         : isNull(true)
-        , lowerOpen(false)
-        , upperOpen(false)
     {
     }
 
@@ -54,8 +52,6 @@
 
     IDBKeyRangeData(IDBKeyRange* keyRange)
         : isNull(!keyRange)
-        , lowerOpen(false)
-        , upperOpen(false)
     {
         if (isNull)
             return;
@@ -77,14 +73,14 @@
     template<class Encoder> void encode(Encoder&) const;
     template<class Decoder> static WARN_UNUSED_RETURN bool decode(Decoder&, IDBKeyRangeData&);
 
-    bool isNull;
-
     IDBKeyData lowerKey;
     IDBKeyData upperKey;
 
-    bool lowerOpen;
-    bool upperOpen;
+    bool lowerOpen { false };
+    bool upperOpen { false };
 
+    bool isNull;
+
 #if !LOG_DISABLED
     String loggingString() const;
 #endif

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBObjectStore.h (275546 => 275547)


--- trunk/Source/WebCore/Modules/indexeddb/IDBObjectStore.h	2021-04-06 20:39:10 UTC (rev 275546)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBObjectStore.h	2021-04-06 20:43:00 UTC (rev 275547)
@@ -50,7 +50,7 @@
 struct IDBKeyRangeData;
 
 namespace IndexedDB {
-enum class ObjectStoreOverwriteMode;
+enum class ObjectStoreOverwriteMode : uint8_t;
 }
 
 class IDBObjectStore final : public ActiveDOMObject {

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBOpenDBRequest.cpp (275546 => 275547)


--- trunk/Source/WebCore/Modules/indexeddb/IDBOpenDBRequest.cpp	2021-04-06 20:39:10 UTC (rev 275546)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBOpenDBRequest.cpp	2021-04-06 20:43:00 UTC (rev 275547)
@@ -55,11 +55,10 @@
 }
     
 IDBOpenDBRequest::IDBOpenDBRequest(ScriptExecutionContext& context, IDBClient::IDBConnectionProxy& connectionProxy, const IDBDatabaseIdentifier& databaseIdentifier, uint64_t version, IndexedDB::RequestType requestType)
-    : IDBRequest(context, connectionProxy)
+    : IDBRequest(context, connectionProxy, requestType)
     , m_databaseIdentifier(databaseIdentifier)
     , m_version(version)
 {
-    m_requestType = requestType;
 }
 
 IDBOpenDBRequest::~IDBOpenDBRequest()
@@ -81,7 +80,7 @@
 
     // 3.3.7 "versionchange" transaction steps
     // When the transaction is finished, after firing complete/abort on the transaction, immediately set request's transaction property to null.
-    m_shouldExposeTransactionToDOM = false;
+    setShouldExposeTransactionToDOM(false);
 }
 
 void IDBOpenDBRequest::fireSuccessAfterVersionChangeCommit()
@@ -137,7 +136,7 @@
     ASSERT(canCurrentThreadAccessThreadLocalData(originThread()));
 
     setResult(IDBDatabase::create(*scriptExecutionContext(), connectionProxy(), resultData));
-    m_readyState = ReadyState::Done;
+    setReadyState(ReadyState::Done);
 
     enqueueEvent(IDBRequestCompletionEvent::create(eventNames().successEvent, Event::CanBubble::No, Event::IsCancelable::No, *this));
 }
@@ -158,7 +157,7 @@
     LOG(IndexedDB, "IDBOpenDBRequest::onUpgradeNeeded() - current version is %" PRIu64 ", new is %" PRIu64, oldVersion, newVersion);
 
     setResult(WTFMove(database));
-    m_readyState = ReadyState::Done;
+    setReadyState(ReadyState::Done);
     m_transaction = WTFMove(transaction);
     m_transaction->addRequest(*this);
 
@@ -173,7 +172,7 @@
 
     LOG(IndexedDB, "IDBOpenDBRequest::onDeleteDatabaseSuccess() - current version is %" PRIu64, oldVersion);
 
-    m_readyState = ReadyState::Done;
+    setReadyState(ReadyState::Done);
     setResultToUndefined();
 
     enqueueEvent(IDBVersionChangeEvent::create(oldVersion, 0, eventNames().successEvent));

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBRequest.cpp (275546 => 275547)


--- trunk/Source/WebCore/Modules/indexeddb/IDBRequest.cpp	2021-04-06 20:39:10 UTC (rev 275546)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBRequest.cpp	2021-04-06 20:43:00 UTC (rev 275547)
@@ -81,12 +81,13 @@
     return adoptRef(*new IDBRequest(context, index, requestedRecordType, transaction));
 }
 
-IDBRequest::IDBRequest(ScriptExecutionContext& context, IDBClient::IDBConnectionProxy& connectionProxy)
+IDBRequest::IDBRequest(ScriptExecutionContext& context, IDBClient::IDBConnectionProxy& connectionProxy, IndexedDB::RequestType requestType)
     : IDBActiveDOMObject(&context)
     , m_resourceIdentifier(connectionProxy)
+    , m_result(NullResultType::Undefined)
     , m_connectionProxy(connectionProxy)
+    , m_requestType(requestType)
 {
-    m_result = NullResultType::Undefined;
     suspendIfNeeded();
 }
 
@@ -94,10 +95,10 @@
     : IDBActiveDOMObject(&context)
     , m_transaction(&transaction)
     , m_resourceIdentifier(transaction.connectionProxy())
+    , m_result(NullResultType::Undefined)
     , m_source(&objectStore)
     , m_connectionProxy(transaction.database().connectionProxy())
 {
-    m_result = NullResultType::Undefined;
     suspendIfNeeded();
 }
 
@@ -105,6 +106,7 @@
     : IDBActiveDOMObject(&context)
     , m_transaction(&transaction)
     , m_resourceIdentifier(transaction.connectionProxy())
+    , m_result(NullResultType::Undefined)
     , m_pendingCursor(&cursor)
     , m_connectionProxy(transaction.database().connectionProxy())
 {
@@ -114,7 +116,6 @@
         [this] (const auto& value) { this->m_source = IDBRequest::Source { value }; }
     );
 
-    m_result = NullResultType::Undefined;
     cursor.setRequest(*this);
 }
 
@@ -122,10 +123,10 @@
     : IDBActiveDOMObject(&context)
     , m_transaction(&transaction)
     , m_resourceIdentifier(transaction.connectionProxy())
+    , m_result(NullResultType::Undefined)
     , m_source(&index)
     , m_connectionProxy(transaction.database().connectionProxy())
 {
-    m_result = NullResultType::Undefined;
     suspendIfNeeded();
 }
 
@@ -133,11 +134,11 @@
     : IDBActiveDOMObject(&context)
     , m_transaction(&transaction)
     , m_resourceIdentifier(transaction.connectionProxy())
+    , m_result(NullResultType::Undefined)
     , m_source(&objectStore)
+    , m_connectionProxy(transaction.database().connectionProxy())
     , m_requestedObjectStoreRecordType(type)
-    , m_connectionProxy(transaction.database().connectionProxy())
 {
-    m_result = NullResultType::Undefined;
     suspendIfNeeded();
 }
 
@@ -144,7 +145,6 @@
 IDBRequest::IDBRequest(ScriptExecutionContext& context, IDBIndex& index, IndexedDB::IndexRecordType requestedRecordType, IDBTransaction& transaction)
     : IDBRequest(context, index, transaction)
 {
-    m_result = NullResultType::Undefined;
     m_requestedIndexRecordType = requestedRecordType;
 }
 

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBRequest.h (275546 => 275547)


--- trunk/Source/WebCore/Modules/indexeddb/IDBRequest.h	2021-04-06 20:39:10 UTC (rev 275546)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBRequest.h	2021-04-06 20:43:00 UTC (rev 275547)
@@ -126,24 +126,18 @@
     void setTransactionOperationID(uint64_t transactionOperationID) { m_currentTransactionOperationID = transactionOperationID; }
 
 protected:
-    IDBRequest(ScriptExecutionContext&, IDBClient::IDBConnectionProxy&);
+    IDBRequest(ScriptExecutionContext&, IDBClient::IDBConnectionProxy&, IndexedDB::RequestType);
 
     void enqueueEvent(Ref<Event>&&);
     void dispatchEvent(Event&) override;
 
     void setResult(Ref<IDBDatabase>&&);
+    void setReadyState(ReadyState state) { m_readyState = state; }
+    
+    void setShouldExposeTransactionToDOM(bool shouldExposeTransactionToDOM) { m_shouldExposeTransactionToDOM = shouldExposeTransactionToDOM; }
 
     IDBClient::IDBConnectionProxy& connectionProxy() { return m_connectionProxy.get(); }
 
-    // FIXME: Protected data members aren't great for maintainability.
-    // Consider adding protected helper functions and making these private.
-    ReadyState m_readyState { ReadyState::Pending };
-    RefPtr<IDBTransaction> m_transaction;
-    bool m_shouldExposeTransactionToDOM { true };
-    RefPtr<DOMException> m_domError;
-    IndexedDB::RequestType m_requestType { IndexedDB::RequestType::Other };
-    Event* m_openDatabaseSuccessEvent { nullptr };
-
 private:
     IDBRequest(ScriptExecutionContext&, IDBObjectStore&, IDBTransaction&);
     IDBRequest(ScriptExecutionContext&, IDBCursor&, IDBTransaction&);
@@ -171,6 +165,14 @@
 
     void clearWrappers();
 
+protected:
+    // FIXME: Protected data members aren't great for maintainability.
+    // Consider adding protected helper functions and making these private.
+    RefPtr<IDBTransaction> m_transaction;
+    RefPtr<DOMException> m_domError;
+    Event* m_openDatabaseSuccessEvent { nullptr };
+
+private:
     IDBCursor* resultCursor();
 
     IDBError m_idbError;
@@ -178,21 +180,24 @@
 
     JSValueInWrappedObject m_resultWrapper;
     JSValueInWrappedObject m_cursorWrapper;
+
+    uint64_t m_currentTransactionOperationID { 0 };
+
     Result m_result;
     Optional<Source> m_source;
 
-    bool m_hasPendingActivity { true };
+    RefPtr<IDBCursor> m_pendingCursor;
+    Ref<IDBClient::IDBConnectionProxy> m_connectionProxy;
+
+    ReadyState m_readyState { ReadyState::Pending };
+    IndexedDB::RequestType m_requestType { IndexedDB::RequestType::Other };
     IndexedDB::ObjectStoreRecordType m_requestedObjectStoreRecordType { IndexedDB::ObjectStoreRecordType::ValueOnly };
     IndexedDB::IndexRecordType m_requestedIndexRecordType { IndexedDB::IndexRecordType::Key };
 
-    RefPtr<IDBCursor> m_pendingCursor;
-
-    Ref<IDBClient::IDBConnectionProxy> m_connectionProxy;
-
+    bool m_shouldExposeTransactionToDOM { true };
+    bool m_hasPendingActivity { true };
     bool m_dispatchingEvent { false };
     bool m_hasUncaughtException { false };
-
-    uint64_t m_currentTransactionOperationID { 0 };
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/Modules/indexeddb/IndexedDB.h (275546 => 275547)


--- trunk/Source/WebCore/Modules/indexeddb/IndexedDB.h	2021-04-06 20:39:10 UTC (rev 275546)
+++ trunk/Source/WebCore/Modules/indexeddb/IndexedDB.h	2021-04-06 20:43:00 UTC (rev 275547)
@@ -32,7 +32,7 @@
 
 namespace IndexedDB {
 
-enum class TransactionState {
+enum class TransactionState : uint8_t {
     Active,
     Inactive,
     Committing,
@@ -40,7 +40,7 @@
     Finished,
 };
 
-enum class CursorDirection {
+enum class CursorDirection : uint8_t {
     Next,
     Nextunique,
     Prev,
@@ -49,8 +49,8 @@
 const unsigned CursorDirectionMaximum = 3;
 
 enum class CursorType : bool {
-    KeyAndValue = 0,
-    KeyOnly = 1,
+    KeyAndValue,
+    KeyOnly,
 };
 const unsigned CursorTypeMaximum = 1;
 
@@ -59,12 +59,12 @@
     ObjectStore,
 };
 
-enum class VersionNullness {
+enum class VersionNullness : uint8_t {
     Null,
     NonNull,
 };
 
-enum class ObjectStoreOverwriteMode {
+enum class ObjectStoreOverwriteMode : uint8_t {
     Overwrite,
     OverwriteForCursor,
     NoOverwrite,
@@ -75,7 +75,7 @@
     Value,
 };
 
-enum class ObjectStoreRecordType {
+enum class ObjectStoreRecordType : uint8_t {
     ValueOnly,
     KeyOnly,
 };
@@ -92,13 +92,13 @@
     Min,
 };
 
-enum class RequestType {
+enum class RequestType : uint8_t {
     Open,
     Delete,
     Other,
 };
 
-enum class GetAllType {
+enum class GetAllType : uint8_t {
     Keys,
     Values,
 };

Modified: trunk/Source/WebCore/Modules/indexeddb/client/IDBConnectionToServerDelegate.h (275546 => 275547)


--- trunk/Source/WebCore/Modules/indexeddb/client/IDBConnectionToServerDelegate.h	2021-04-06 20:39:10 UTC (rev 275546)
+++ trunk/Source/WebCore/Modules/indexeddb/client/IDBConnectionToServerDelegate.h	2021-04-06 20:43:00 UTC (rev 275547)
@@ -46,7 +46,7 @@
 struct SecurityOriginData;
 
 namespace IndexedDB {
-enum class ObjectStoreOverwriteMode;
+enum class ObjectStoreOverwriteMode : uint8_t;
 enum class ConnectionClosedOnBehalfOfServer : bool;
 }
 

Modified: trunk/Source/WebCore/Modules/indexeddb/server/MemoryIndex.h (275546 => 275547)


--- trunk/Source/WebCore/Modules/indexeddb/server/MemoryIndex.h	2021-04-06 20:39:10 UTC (rev 275546)
+++ trunk/Source/WebCore/Modules/indexeddb/server/MemoryIndex.h	2021-04-06 20:43:00 UTC (rev 275547)
@@ -43,7 +43,7 @@
 struct IDBKeyRangeData;
 
 namespace IndexedDB {
-enum class GetAllType;
+enum class GetAllType : uint8_t;
 enum class IndexRecordType : bool;
 }
 

Modified: trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.h (275546 => 275547)


--- trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.h	2021-04-06 20:39:10 UTC (rev 275546)
+++ trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.h	2021-04-06 20:43:00 UTC (rev 275547)
@@ -49,7 +49,7 @@
 struct IDBKeyRangeData;
 
 namespace IndexedDB {
-enum class GetAllType;
+enum class GetAllType : uint8_t;
 enum class IndexRecordType : bool;
 }
 

Modified: trunk/Source/WebCore/Modules/indexeddb/shared/IDBCursorInfo.h (275546 => 275547)


--- trunk/Source/WebCore/Modules/indexeddb/shared/IDBCursorInfo.h	2021-04-06 20:39:10 UTC (rev 275546)
+++ trunk/Source/WebCore/Modules/indexeddb/shared/IDBCursorInfo.h	2021-04-06 20:43:00 UTC (rev 275547)
@@ -33,7 +33,7 @@
 class IDBTransaction;
 
 namespace IndexedDB {
-enum class CursorDirection;
+enum class CursorDirection : uint8_t;
 enum class CursorSource : bool;
 enum class CursorType : bool;
 }

Modified: trunk/Source/WebCore/Modules/indexeddb/shared/IDBGetAllRecordsData.h (275546 => 275547)


--- trunk/Source/WebCore/Modules/indexeddb/shared/IDBGetAllRecordsData.h	2021-04-06 20:39:10 UTC (rev 275546)
+++ trunk/Source/WebCore/Modules/indexeddb/shared/IDBGetAllRecordsData.h	2021-04-06 20:43:00 UTC (rev 275547)
@@ -31,8 +31,7 @@
 namespace WebCore {
 
 namespace IndexedDB {
-enum class DataSource;
-enum class GetAllType;
+enum class GetAllType : uint8_t;
 }
 
 struct IDBGetAllRecordsData {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to