Changeset 242054 in webkit


Ignore:
Timestamp:
Feb 25, 2019 12:15:53 PM (5 years ago)
Author:
Tadeu Zagallo
Message:

Avoid hashing CompactVariableEnvironment when decoding CompactVariableMap::Handle
https://bugs.webkit.org/show_bug.cgi?id=194937

Reviewed by Saam Barati.

Hashing the CompactVariableEnvironment is expensive and we could avoid it
when decoding multiple handles to the same environment. This is sound because
a pointer to the same CompactVariableEnvironment will hash the same.

  • runtime/CachedTypes.cpp:

(JSC::Decoder::handleForEnvironment const):
(JSC::Decoder::setHandleForEnvironment):
(JSC::CachedCompactVariableMapHandle::decode const):

Location:
trunk/Source/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r242053 r242054  
     12019-02-25  Tadeu Zagallo  <tzagallo@apple.com>
     2
     3        Avoid hashing CompactVariableEnvironment when decoding CompactVariableMap::Handle
     4        https://bugs.webkit.org/show_bug.cgi?id=194937
     5
     6        Reviewed by Saam Barati.
     7
     8        Hashing the CompactVariableEnvironment is expensive and we could avoid it
     9        when decoding multiple handles to the same environment. This is sound because
     10        a pointer to the same CompactVariableEnvironment will hash the same.
     11
     12        * runtime/CachedTypes.cpp:
     13        (JSC::Decoder::handleForEnvironment const):
     14        (JSC::Decoder::setHandleForEnvironment):
     15        (JSC::CachedCompactVariableMapHandle::decode const):
     16
    1172019-02-25  Tadeu Zagallo  <tzagallo@apple.com>
    218
  • trunk/Source/JavaScriptCore/runtime/CachedTypes.cpp

    r242053 r242054  
    260260    }
    261261
     262    CompactVariableMap::Handle handleForEnvironment(CompactVariableEnvironment* environment) const
     263    {
     264        auto it = m_environmentToHandleMap.find(environment);
     265        ASSERT(it != m_environmentToHandleMap.end());
     266        return it->value;
     267    }
     268
     269    void setHandleForEnvironment(CompactVariableEnvironment* environment, const CompactVariableMap::Handle& handle)
     270    {
     271        auto addResult = m_environmentToHandleMap.add(environment, handle);
     272        ASSERT_UNUSED(addResult, addResult.isNewEntry);
     273    }
     274
    262275private:
    263276    VM& m_vm;
     
    268281    HashMap<ptrdiff_t, void*> m_offsetToPtrMap;
    269282    Vector<std::function<void()>> m_finalizers;
     283    HashMap<CompactVariableEnvironment*, CompactVariableMap::Handle> m_environmentToHandleMap;
    270284};
    271285
     
    939953        bool isNewAllocation;
    940954        CompactVariableEnvironment* environment = m_environment.decode(decoder, isNewAllocation);
     955        if (!isNewAllocation)
     956            return decoder.handleForEnvironment(environment);
    941957        bool isNewEntry;
    942958        CompactVariableMap::Handle handle = decoder.vm().m_compactVariableMap->get(environment, isNewEntry);
    943         if (!isNewAllocation)
    944             ASSERT(!isNewEntry);
    945         else if (!isNewEntry) {
     959        if (!isNewEntry) {
    946960            decoder.addFinalizer([=] {
    947961                delete environment;
    948962            });
    949963        }
     964        decoder.setHandleForEnvironment(environment, handle);
    950965        return handle;
    951966    }
Note: See TracChangeset for help on using the changeset viewer.