Changeset 275547 in webkit


Ignore:
Timestamp:
Apr 6, 2021 1:43:00 PM (3 years ago)
Author:
Simon Fraser
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:
Location:
trunk/Source/WebCore
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r275543 r275547  
     12021-04-06  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Shrink some IndexedDB-related classes
     4        https://bugs.webkit.org/show_bug.cgi?id=224221
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Shrink some enum classes, and re-order data members to optimize packing in
     9        IDBRequest and IDBKeyRangeData.
     10
     11        A couple of data members of IDBRequest were made private with protected setters.
     12
     13        This shrinks IDBRequest from 496 bytes to 448 bytes, and IDBKeyRangeData from 96
     14        to 72 bytes on x86_64.
     15
     16        * Modules/indexeddb/IDBKeyData.h:
     17        * Modules/indexeddb/IDBKeyRangeData.cpp:
     18        (WebCore::IDBKeyRangeData::IDBKeyRangeData):
     19        * Modules/indexeddb/IDBKeyRangeData.h:
     20        (WebCore::IDBKeyRangeData::IDBKeyRangeData):
     21        * Modules/indexeddb/IDBObjectStore.h:
     22        * Modules/indexeddb/IDBOpenDBRequest.cpp:
     23        (WebCore::IDBOpenDBRequest::IDBOpenDBRequest):
     24        (WebCore::IDBOpenDBRequest::versionChangeTransactionDidFinish):
     25        (WebCore::IDBOpenDBRequest::onSuccess):
     26        (WebCore::IDBOpenDBRequest::onUpgradeNeeded):
     27        (WebCore::IDBOpenDBRequest::onDeleteDatabaseSuccess):
     28        * Modules/indexeddb/IDBRequest.cpp:
     29        (WebCore::IDBRequest::IDBRequest):
     30        * Modules/indexeddb/IDBRequest.h:
     31        (WebCore::IDBRequest::setReadyState):
     32        (WebCore::IDBRequest::setShouldExposeTransactionToDOM):
     33        * Modules/indexeddb/IndexedDB.h:
     34        * Modules/indexeddb/client/IDBConnectionToServerDelegate.h:
     35        * Modules/indexeddb/server/MemoryIndex.h:
     36        * Modules/indexeddb/server/MemoryObjectStore.h:
     37        * Modules/indexeddb/shared/IDBCursorInfo.h:
     38        * Modules/indexeddb/shared/IDBGetAllRecordsData.h:
     39
    1402021-04-06  Ryosuke Niwa  <rniwa@webkit.org>
    241
  • trunk/Source/WebCore/Modules/indexeddb/IDBKeyData.h

    r275151 r275547  
    192192
    193193    IndexedDB::KeyType m_type;
    194     Variant<Vector<IDBKeyData>, String, double, ThreadSafeDataBuffer> m_value;
    195 
    196194    bool m_isNull { false };
    197195    bool m_isDeletedValue { false };
     196
     197    Variant<Vector<IDBKeyData>, String, double, ThreadSafeDataBuffer> m_value;
    198198};
    199199
  • trunk/Source/WebCore/Modules/indexeddb/IDBKeyRangeData.cpp

    r275151 r275547  
    3232
    3333IDBKeyRangeData::IDBKeyRangeData(IDBKey* key)
    34     : isNull(!key)
    35     , lowerKey(key)
     34    : lowerKey(key)
    3635    , upperKey(key)
    37     , lowerOpen(false)
    38     , upperOpen(false)
     36    , isNull(!key)
    3937{
    4038}
    4139
    4240IDBKeyRangeData::IDBKeyRangeData(const IDBKeyData& keyData)
    43     : isNull(keyData.isNull())
    44     , lowerKey(keyData)
     41    : lowerKey(keyData)
    4542    , upperKey(keyData)
    46     , lowerOpen(false)
    47     , upperOpen(false)
     43    , isNull(keyData.isNull())
    4844{
    4945}
  • trunk/Source/WebCore/Modules/indexeddb/IDBKeyRangeData.h

    r275151 r275547  
    3636    IDBKeyRangeData()
    3737        : isNull(true)
    38         , lowerOpen(false)
    39         , upperOpen(false)
    4038    {
    4139    }
     
    5553    IDBKeyRangeData(IDBKeyRange* keyRange)
    5654        : isNull(!keyRange)
    57         , lowerOpen(false)
    58         , upperOpen(false)
    5955    {
    6056        if (isNull)
     
    7874    template<class Decoder> static WARN_UNUSED_RETURN bool decode(Decoder&, IDBKeyRangeData&);
    7975
    80     bool isNull;
    81 
    8276    IDBKeyData lowerKey;
    8377    IDBKeyData upperKey;
    8478
    85     bool lowerOpen;
    86     bool upperOpen;
     79    bool lowerOpen { false };
     80    bool upperOpen { false };
     81
     82    bool isNull;
    8783
    8884#if !LOG_DISABLED
  • trunk/Source/WebCore/Modules/indexeddb/IDBObjectStore.h

    r275151 r275547  
    5151
    5252namespace IndexedDB {
    53 enum class ObjectStoreOverwriteMode;
     53enum class ObjectStoreOverwriteMode : uint8_t;
    5454}
    5555
  • trunk/Source/WebCore/Modules/indexeddb/IDBOpenDBRequest.cpp

    r275151 r275547  
    5656   
    5757IDBOpenDBRequest::IDBOpenDBRequest(ScriptExecutionContext& context, IDBClient::IDBConnectionProxy& connectionProxy, const IDBDatabaseIdentifier& databaseIdentifier, uint64_t version, IndexedDB::RequestType requestType)
    58     : IDBRequest(context, connectionProxy)
     58    : IDBRequest(context, connectionProxy, requestType)
    5959    , m_databaseIdentifier(databaseIdentifier)
    6060    , m_version(version)
    6161{
    62     m_requestType = requestType;
    6362}
    6463
     
    8281    // 3.3.7 "versionchange" transaction steps
    8382    // When the transaction is finished, after firing complete/abort on the transaction, immediately set request's transaction property to null.
    84     m_shouldExposeTransactionToDOM = false;
     83    setShouldExposeTransactionToDOM(false);
    8584}
    8685
     
    138137
    139138    setResult(IDBDatabase::create(*scriptExecutionContext(), connectionProxy(), resultData));
    140     m_readyState = ReadyState::Done;
     139    setReadyState(ReadyState::Done);
    141140
    142141    enqueueEvent(IDBRequestCompletionEvent::create(eventNames().successEvent, Event::CanBubble::No, Event::IsCancelable::No, *this));
     
    159158
    160159    setResult(WTFMove(database));
    161     m_readyState = ReadyState::Done;
     160    setReadyState(ReadyState::Done);
    162161    m_transaction = WTFMove(transaction);
    163162    m_transaction->addRequest(*this);
     
    174173    LOG(IndexedDB, "IDBOpenDBRequest::onDeleteDatabaseSuccess() - current version is %" PRIu64, oldVersion);
    175174
    176     m_readyState = ReadyState::Done;
     175    setReadyState(ReadyState::Done);
    177176    setResultToUndefined();
    178177
  • trunk/Source/WebCore/Modules/indexeddb/IDBRequest.cpp

    r275151 r275547  
    8282}
    8383
    84 IDBRequest::IDBRequest(ScriptExecutionContext& context, IDBClient::IDBConnectionProxy& connectionProxy)
     84IDBRequest::IDBRequest(ScriptExecutionContext& context, IDBClient::IDBConnectionProxy& connectionProxy, IndexedDB::RequestType requestType)
    8585    : IDBActiveDOMObject(&context)
    8686    , m_resourceIdentifier(connectionProxy)
     87    , m_result(NullResultType::Undefined)
    8788    , m_connectionProxy(connectionProxy)
    88 {
    89     m_result = NullResultType::Undefined;
     89    , m_requestType(requestType)
     90{
    9091    suspendIfNeeded();
    9192}
     
    9596    , m_transaction(&transaction)
    9697    , m_resourceIdentifier(transaction.connectionProxy())
     98    , m_result(NullResultType::Undefined)
    9799    , m_source(&objectStore)
    98100    , m_connectionProxy(transaction.database().connectionProxy())
    99101{
    100     m_result = NullResultType::Undefined;
    101102    suspendIfNeeded();
    102103}
     
    106107    , m_transaction(&transaction)
    107108    , m_resourceIdentifier(transaction.connectionProxy())
     109    , m_result(NullResultType::Undefined)
    108110    , m_pendingCursor(&cursor)
    109111    , m_connectionProxy(transaction.database().connectionProxy())
     
    115117    );
    116118
    117     m_result = NullResultType::Undefined;
    118119    cursor.setRequest(*this);
    119120}
     
    123124    , m_transaction(&transaction)
    124125    , m_resourceIdentifier(transaction.connectionProxy())
     126    , m_result(NullResultType::Undefined)
    125127    , m_source(&index)
    126128    , m_connectionProxy(transaction.database().connectionProxy())
    127129{
    128     m_result = NullResultType::Undefined;
    129130    suspendIfNeeded();
    130131}
     
    134135    , m_transaction(&transaction)
    135136    , m_resourceIdentifier(transaction.connectionProxy())
     137    , m_result(NullResultType::Undefined)
    136138    , m_source(&objectStore)
     139    , m_connectionProxy(transaction.database().connectionProxy())
    137140    , m_requestedObjectStoreRecordType(type)
    138     , m_connectionProxy(transaction.database().connectionProxy())
    139 {
    140     m_result = NullResultType::Undefined;
     141{
    141142    suspendIfNeeded();
    142143}
     
    145146    : IDBRequest(context, index, transaction)
    146147{
    147     m_result = NullResultType::Undefined;
    148148    m_requestedIndexRecordType = requestedRecordType;
    149149}
  • trunk/Source/WebCore/Modules/indexeddb/IDBRequest.h

    r275151 r275547  
    127127
    128128protected:
    129     IDBRequest(ScriptExecutionContext&, IDBClient::IDBConnectionProxy&);
     129    IDBRequest(ScriptExecutionContext&, IDBClient::IDBConnectionProxy&, IndexedDB::RequestType);
    130130
    131131    void enqueueEvent(Ref<Event>&&);
     
    133133
    134134    void setResult(Ref<IDBDatabase>&&);
     135    void setReadyState(ReadyState state) { m_readyState = state; }
     136   
     137    void setShouldExposeTransactionToDOM(bool shouldExposeTransactionToDOM) { m_shouldExposeTransactionToDOM = shouldExposeTransactionToDOM; }
    135138
    136139    IDBClient::IDBConnectionProxy& connectionProxy() { return m_connectionProxy.get(); }
    137 
    138     // FIXME: Protected data members aren't great for maintainability.
    139     // Consider adding protected helper functions and making these private.
    140     ReadyState m_readyState { ReadyState::Pending };
    141     RefPtr<IDBTransaction> m_transaction;
    142     bool m_shouldExposeTransactionToDOM { true };
    143     RefPtr<DOMException> m_domError;
    144     IndexedDB::RequestType m_requestType { IndexedDB::RequestType::Other };
    145     Event* m_openDatabaseSuccessEvent { nullptr };
    146140
    147141private:
     
    172166    void clearWrappers();
    173167
     168protected:
     169    // FIXME: Protected data members aren't great for maintainability.
     170    // Consider adding protected helper functions and making these private.
     171    RefPtr<IDBTransaction> m_transaction;
     172    RefPtr<DOMException> m_domError;
     173    Event* m_openDatabaseSuccessEvent { nullptr };
     174
     175private:
    174176    IDBCursor* resultCursor();
    175177
     
    179181    JSValueInWrappedObject m_resultWrapper;
    180182    JSValueInWrappedObject m_cursorWrapper;
     183
     184    uint64_t m_currentTransactionOperationID { 0 };
     185
    181186    Result m_result;
    182187    Optional<Source> m_source;
    183188
    184     bool m_hasPendingActivity { true };
     189    RefPtr<IDBCursor> m_pendingCursor;
     190    Ref<IDBClient::IDBConnectionProxy> m_connectionProxy;
     191
     192    ReadyState m_readyState { ReadyState::Pending };
     193    IndexedDB::RequestType m_requestType { IndexedDB::RequestType::Other };
    185194    IndexedDB::ObjectStoreRecordType m_requestedObjectStoreRecordType { IndexedDB::ObjectStoreRecordType::ValueOnly };
    186195    IndexedDB::IndexRecordType m_requestedIndexRecordType { IndexedDB::IndexRecordType::Key };
    187196
    188     RefPtr<IDBCursor> m_pendingCursor;
    189 
    190     Ref<IDBClient::IDBConnectionProxy> m_connectionProxy;
    191 
     197    bool m_shouldExposeTransactionToDOM { true };
     198    bool m_hasPendingActivity { true };
    192199    bool m_dispatchingEvent { false };
    193200    bool m_hasUncaughtException { false };
    194 
    195     uint64_t m_currentTransactionOperationID { 0 };
    196201};
    197202
  • trunk/Source/WebCore/Modules/indexeddb/IndexedDB.h

    r275151 r275547  
    3333namespace IndexedDB {
    3434
    35 enum class TransactionState {
     35enum class TransactionState : uint8_t {
    3636    Active,
    3737    Inactive,
     
    4141};
    4242
    43 enum class CursorDirection {
     43enum class CursorDirection : uint8_t {
    4444    Next,
    4545    Nextunique,
     
    5050
    5151enum class CursorType : bool {
    52     KeyAndValue = 0,
    53     KeyOnly = 1,
     52    KeyAndValue,
     53    KeyOnly,
    5454};
    5555const unsigned CursorTypeMaximum = 1;
     
    6060};
    6161
    62 enum class VersionNullness {
     62enum class VersionNullness : uint8_t {
    6363    Null,
    6464    NonNull,
    6565};
    6666
    67 enum class ObjectStoreOverwriteMode {
     67enum class ObjectStoreOverwriteMode : uint8_t {
    6868    Overwrite,
    6969    OverwriteForCursor,
     
    7676};
    7777
    78 enum class ObjectStoreRecordType {
     78enum class ObjectStoreRecordType : uint8_t {
    7979    ValueOnly,
    8080    KeyOnly,
     
    9393};
    9494
    95 enum class RequestType {
     95enum class RequestType : uint8_t {
    9696    Open,
    9797    Delete,
     
    9999};
    100100
    101 enum class GetAllType {
     101enum class GetAllType : uint8_t {
    102102    Keys,
    103103    Values,
  • trunk/Source/WebCore/Modules/indexeddb/client/IDBConnectionToServerDelegate.h

    r275151 r275547  
    4747
    4848namespace IndexedDB {
    49 enum class ObjectStoreOverwriteMode;
     49enum class ObjectStoreOverwriteMode : uint8_t;
    5050enum class ConnectionClosedOnBehalfOfServer : bool;
    5151}
  • trunk/Source/WebCore/Modules/indexeddb/server/MemoryIndex.h

    r275151 r275547  
    4444
    4545namespace IndexedDB {
    46 enum class GetAllType;
     46enum class GetAllType : uint8_t;
    4747enum class IndexRecordType : bool;
    4848}
  • trunk/Source/WebCore/Modules/indexeddb/server/MemoryObjectStore.h

    r275151 r275547  
    5050
    5151namespace IndexedDB {
    52 enum class GetAllType;
     52enum class GetAllType : uint8_t;
    5353enum class IndexRecordType : bool;
    5454}
  • trunk/Source/WebCore/Modules/indexeddb/shared/IDBCursorInfo.h

    r275151 r275547  
    3434
    3535namespace IndexedDB {
    36 enum class CursorDirection;
     36enum class CursorDirection : uint8_t;
    3737enum class CursorSource : bool;
    3838enum class CursorType : bool;
  • trunk/Source/WebCore/Modules/indexeddb/shared/IDBGetAllRecordsData.h

    r275151 r275547  
    3232
    3333namespace IndexedDB {
    34 enum class DataSource;
    35 enum class GetAllType;
     34enum class GetAllType : uint8_t;
    3635}
    3736
Note: See TracChangeset for help on using the changeset viewer.