⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 243702 in webkit


Ignore:
Timestamp:
Apr 1, 2019, 11:33:45 AM (7 years ago)
Author:
ysuzuki@apple.com
Message:

[JSC] JSRunLoopTimer::Manager should be small
https://bugs.webkit.org/show_bug.cgi?id=196425

Reviewed by Darin Adler.

Using very large Key or Value in HashMap potentially bloats memory since HashMap pre-allocates large size of
memory ((sizeof(Key) + sizeof(Value)) * N) for its backing storage's array. Using std::unique_ptr<> for JSRunLoopTimer's
PerVMData to keep HashMap's backing store size small.

  • runtime/JSRunLoopTimer.cpp:

(JSC::JSRunLoopTimer::Manager::timerDidFire):
(JSC::JSRunLoopTimer::Manager::registerVM):
(JSC::JSRunLoopTimer::Manager::scheduleTimer):
(JSC::JSRunLoopTimer::Manager::cancelTimer):
(JSC::JSRunLoopTimer::Manager::timeUntilFire):
(JSC::JSRunLoopTimer::Manager::didChangeRunLoop):

  • runtime/JSRunLoopTimer.h:
Location:
trunk/Source/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r243700 r243702  
     12019-04-01  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        [JSC] JSRunLoopTimer::Manager should be small
     4        https://bugs.webkit.org/show_bug.cgi?id=196425
     5
     6        Reviewed by Darin Adler.
     7
     8        Using very large Key or Value in HashMap potentially bloats memory since HashMap pre-allocates large size of
     9        memory ((sizeof(Key) + sizeof(Value)) * N) for its backing storage's array. Using std::unique_ptr<> for JSRunLoopTimer's
     10        PerVMData to keep HashMap's backing store size small.
     11
     12        * runtime/JSRunLoopTimer.cpp:
     13        (JSC::JSRunLoopTimer::Manager::timerDidFire):
     14        (JSC::JSRunLoopTimer::Manager::registerVM):
     15        (JSC::JSRunLoopTimer::Manager::scheduleTimer):
     16        (JSC::JSRunLoopTimer::Manager::cancelTimer):
     17        (JSC::JSRunLoopTimer::Manager::timeUntilFire):
     18        (JSC::JSRunLoopTimer::Manager::didChangeRunLoop):
     19        * runtime/JSRunLoopTimer.h:
     20
    1212019-04-01  Stephan Szabo  <stephan.szabo@sony.com>
    222
  • trunk/Source/JavaScriptCore/runtime/JSRunLoopTimer.cpp

    r239427 r243702  
    122122        EpochTime nowEpochTime = epochTime(0_s);
    123123        for (auto& entry : m_mapping) {
    124             PerVMData& data = entry.value;
     124            PerVMData& data = *entry.value;
    125125#if USE(CF)
    126126            if (data.runLoop.get() != currentRunLoop)
     
    173173void JSRunLoopTimer::Manager::registerVM(VM& vm)
    174174{
    175     PerVMData data { *this };
    176 #if USE(CF)
    177     data.setRunLoop(this, vm.runLoop());
     175    auto data = std::make_unique<PerVMData>(*this);
     176#if USE(CF)
     177    data->setRunLoop(this, vm.runLoop());
    178178#endif
    179179
     
    200200    RELEASE_ASSERT(iter != m_mapping.end()); // We don't allow calling this after the VM dies.
    201201
    202     PerVMData& data = iter->value;
     202    PerVMData& data = *iter->value;
    203203    EpochTime scheduleTime = fireEpochTime;
    204204    bool found = false;
     
    230230    }
    231231
    232     PerVMData& data = iter->value;
     232    PerVMData& data = *iter->value;
    233233    EpochTime scheduleTime = epochTime(s_decade);
    234234    for (unsigned i = 0; i < data.timers.size(); ++i) {
     
    262262    RELEASE_ASSERT(iter != m_mapping.end()); // We only allow this to be called with a live VM.
    263263
    264     PerVMData& data = iter->value;
     264    PerVMData& data = *iter->value;
    265265    for (auto& entry : data.timers) {
    266266        if (entry.first.ptr() == &timer) {
     
    280280    RELEASE_ASSERT(iter != m_mapping.end());
    281281
    282     PerVMData& data = iter->value;
     282    PerVMData& data = *iter->value;
    283283    data.setRunLoop(this, newRunLoop);
    284284}
  • trunk/Source/JavaScriptCore/runtime/JSRunLoopTimer.h

    r241923 r243702  
    7979
    8080        struct PerVMData {
    81             PerVMData() = default;
    8281#if USE(CF)
    8382            PerVMData(Manager&) { }
     
    8584            PerVMData(Manager&);
    8685#endif
    87             PerVMData(PerVMData&&) = default;
    88             PerVMData& operator=(PerVMData&&) = default;
    89 
    9086            ~PerVMData();
    9187
     
    10298        };
    10399
    104         HashMap<Ref<JSLock>, PerVMData> m_mapping;
     100        HashMap<Ref<JSLock>, std::unique_ptr<PerVMData>> m_mapping;
    105101    };
    106102
Note: See TracChangeset for help on using the changeset viewer.