Changeset 122099 in webkit


Ignore:
Timestamp:
Jul 9, 2012 1:53:48 AM (12 years ago)
Author:
morrita@google.com
Message:

[Chromium] ContextFeaturesClient::isEnabled is slow
https://bugs.webkit.org/show_bug.cgi?id=90367

Reviewed by Kent Tamura.

Source/WebCore:

  • dom/ContextFeatures.h:

(WebCore::ContextFeaturesClient::urlDidChange): Added.
(WebCore::ContextFeatures::urlDidChange): Added.
(WebCore):

  • dom/Document.cpp:

(WebCore::Document::setURL): Added an urlDidChange() call.

Source/WebKit/chromium:

ContextFeaturesClientImpl::isEnabled touches a heavy part in chrome
where locks are acquired for each invocation.

This change introduces a set of caches to avoid such slow calls.
The cache class ContextFeaturesCache is implemented as a
Supplement of ScriptExecutionContext because the flag bits
depend on the domain of each Document.

  • src/ContextFeaturesClientImpl.cpp:

(ContextFeaturesCache): Added.
(Entry): Added.
(WebKit::ContextFeaturesCache::Entry::Entry):
(WebKit::ContextFeaturesCache::Entry::isEnabled):
(WebKit::ContextFeaturesCache::Entry::set):
(WebKit::ContextFeaturesCache::Entry::needsRefresh):
(WebKit::ContextFeaturesCache::entryFor):
(WebKit):
(WebKit::ContextFeaturesCache::supplementName):
(WebKit::ContextFeaturesCache::from):
(WebKit::ContextFeaturesCache::refreshAgainst):
(WebKit::ContextFeaturesClientImpl::isEnabled):
(WebKit::ContextFeaturesClientImpl::urlDidChange): Added to invoke refrshAgainst.
(WebKit::ContextFeaturesClientImpl::askIfIsEnabled):

  • src/ContextFeaturesClientImpl.h:

(ContextFeaturesClientImpl):

Location:
trunk/Source
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r122096 r122099  
     12012-07-09  MORITA Hajime  <morrita@google.com>
     2
     3        [Chromium] ContextFeaturesClient::isEnabled is slow
     4        https://bugs.webkit.org/show_bug.cgi?id=90367
     5
     6        Reviewed by Kent Tamura.
     7
     8        * dom/ContextFeatures.h:
     9        (WebCore::ContextFeaturesClient::urlDidChange): Added.
     10        (WebCore::ContextFeatures::urlDidChange): Added.
     11        (WebCore):
     12        * dom/Document.cpp:
     13        (WebCore::Document::setURL): Added an urlDidChange() call.
     14
    1152012-07-09  Andrei Onea  <onea@adobe.com>
    216
  • trunk/Source/WebCore/dom/ContextFeatures.h

    r120168 r122099  
    4141public:
    4242    enum FeatureType {
    43         ShadowDOM,
     43        ShadowDOM = 0,
    4444        StyleScoped,
    45         PagePopup
     45        PagePopup,
     46        FeatureTypeSize // Should be the last enetry.
    4647    };
    4748
     
    5556
    5657    bool isEnabled(Document*, FeatureType, bool) const;
     58    void urlDidChange(Document*);
    5759
    5860private:
     
    7880    virtual ~ContextFeaturesClient() { }
    7981    virtual bool isEnabled(Document*, ContextFeatures::FeatureType, bool defaultValue) { return defaultValue; }
     82    virtual void urlDidChange(Document*) { }
    8083};
    8184
     
    9598}
    9699
     100inline void ContextFeatures::urlDidChange(Document* document)
     101{
     102    if (m_client)
     103        return;
     104    m_client->urlDidChange(document);
     105}
     106
    97107} // namespace WebCore
    98108
  • trunk/Source/WebCore/dom/Document.cpp

    r121952 r122099  
    26852685    m_documentURI = m_url.string();
    26862686    updateBaseURL();
     2687    contextFeatures()->urlDidChange(this);
    26872688}
    26882689
  • trunk/Source/WebKit/chromium/ChangeLog

    r122098 r122099  
     12012-07-09  MORITA Hajime  <morrita@google.com>
     2
     3        [Chromium] ContextFeaturesClient::isEnabled is slow
     4        https://bugs.webkit.org/show_bug.cgi?id=90367
     5
     6        Reviewed by Kent Tamura.
     7
     8        ContextFeaturesClientImpl::isEnabled touches a heavy part in chrome
     9        where locks are acquired for each invocation.
     10
     11        This change introduces a set of caches to avoid such slow calls.
     12        The cache class ContextFeaturesCache is implemented as a
     13        Supplement of ScriptExecutionContext because the flag bits
     14        depend on the domain of each Document.
     15
     16        * src/ContextFeaturesClientImpl.cpp:
     17        (ContextFeaturesCache): Added.
     18        (Entry): Added.
     19        (WebKit::ContextFeaturesCache::Entry::Entry):
     20        (WebKit::ContextFeaturesCache::Entry::isEnabled):
     21        (WebKit::ContextFeaturesCache::Entry::set):
     22        (WebKit::ContextFeaturesCache::Entry::needsRefresh):
     23        (WebKit::ContextFeaturesCache::entryFor):
     24        (WebKit):
     25        (WebKit::ContextFeaturesCache::supplementName):
     26        (WebKit::ContextFeaturesCache::from):
     27        (WebKit::ContextFeaturesCache::refreshAgainst):
     28        (WebKit::ContextFeaturesClientImpl::isEnabled):
     29        (WebKit::ContextFeaturesClientImpl::urlDidChange): Added to invoke refrshAgainst.
     30        (WebKit::ContextFeaturesClientImpl::askIfIsEnabled):
     31        * src/ContextFeaturesClientImpl.h:
     32        (ContextFeaturesClientImpl):
     33
    1342012-07-09  Vsevolod Vlasov  <vsevik@chromium.org>
    235
  • trunk/Source/WebKit/chromium/src/ContextFeaturesClientImpl.cpp

    r120168 r122099  
    3333
    3434#include "Document.h"
     35#include "SecurityOrigin.h"
    3536#include "WebDocument.h"
    3637#include "WebPermissionClient.h"
    3738
     39using namespace WebCore;
     40
    3841namespace WebKit {
    3942
    40 bool ContextFeaturesClientImpl::isEnabled(WebCore::Document* document, WebCore::ContextFeatures::FeatureType type, bool defaultValue)
     43class ContextFeaturesCache : public Supplement<ScriptExecutionContext> {
     44public:
     45    class Entry {
     46    public:
     47        enum Value {
     48            IsEnabled,
     49            IsDisabled,
     50            NeedsRefresh
     51        };
     52
     53        Entry()
     54            : m_value(NeedsRefresh)
     55            , m_defaultValue(false)
     56        { }
     57
     58        bool isEnabled() const
     59        {
     60            ASSERT(m_value != NeedsRefresh);
     61            return m_value == IsEnabled;
     62        }
     63
     64        void set(bool value, bool defaultValue)
     65        {
     66            m_value = value ? IsEnabled : IsDisabled;
     67            m_defaultValue = defaultValue;
     68        }
     69
     70        bool needsRefresh(bool defaultValue) const
     71        {
     72            return m_value == NeedsRefresh || m_defaultValue != defaultValue;
     73        }
     74
     75    private:
     76        Value m_value;
     77        bool m_defaultValue; // Needs to be traked as a part of the signature since it can be changed dynamically.
     78    };
     79
     80    static const AtomicString& supplementName();
     81    static ContextFeaturesCache* from(Document*);
     82
     83    Entry& entryFor(ContextFeatures::FeatureType type)
     84    {
     85        size_t index = static_cast<size_t>(type);
     86        ASSERT(index < ContextFeatures::FeatureTypeSize);
     87        return m_entries[index];
     88    }
     89
     90    void validateAgainst(Document*);
     91
     92private:
     93    String m_domain;
     94    Entry m_entries[ContextFeatures::FeatureTypeSize];
     95};
     96
     97const AtomicString& ContextFeaturesCache::supplementName()
     98{
     99    DEFINE_STATIC_LOCAL(AtomicString, name, ("ContextFeaturesCache"));
     100    return name;
     101}
     102
     103ContextFeaturesCache* ContextFeaturesCache::from(Document* document)
     104{
     105    ContextFeaturesCache* cache = static_cast<ContextFeaturesCache*>(Supplement<ScriptExecutionContext>::from(document, supplementName()));
     106    if (!cache) {
     107        cache = new ContextFeaturesCache();
     108        Supplement<ScriptExecutionContext>::provideTo(document, supplementName(), adoptPtr(cache));
     109    }
     110
     111    return cache;
     112}
     113
     114void ContextFeaturesCache::validateAgainst(Document* document)
     115{
     116    String currentDomain = document->securityOrigin()->domain();
     117    if (currentDomain == m_domain)
     118        return;
     119    m_domain = currentDomain;
     120    for (size_t i = 0; i < ContextFeatures::FeatureTypeSize; ++i)
     121        m_entries[i] = Entry();
     122}
     123
     124bool ContextFeaturesClientImpl::isEnabled(Document* document, ContextFeatures::FeatureType type, bool defaultValue)
     125{
     126    ContextFeaturesCache::Entry& cache = ContextFeaturesCache::from(document)->entryFor(type);
     127    if (cache.needsRefresh(defaultValue))
     128        cache.set(askIfIsEnabled(document, type, defaultValue), defaultValue);
     129    return cache.isEnabled();
     130}
     131
     132void ContextFeaturesClientImpl::urlDidChange(Document* document)
     133{
     134    ContextFeaturesCache::from(document)->validateAgainst(document);
     135}
     136
     137bool ContextFeaturesClientImpl::askIfIsEnabled(Document* document, ContextFeatures::FeatureType type, bool defaultValue)
    41138{
    42139    if (!m_client)
     
    44141
    45142    switch (type) {
    46     case WebCore::ContextFeatures::ShadowDOM:
    47     case WebCore::ContextFeatures::StyleScoped:
     143    case ContextFeatures::ShadowDOM:
     144    case ContextFeatures::StyleScoped:
    48145        return m_client->allowWebComponents(WebDocument(document), defaultValue);
    49146    default:
  • trunk/Source/WebKit/chromium/src/ContextFeaturesClientImpl.h

    r120168 r122099  
    4545
    4646    virtual bool isEnabled(WebCore::Document*, WebCore::ContextFeatures::FeatureType, bool defaultValue) OVERRIDE;
     47    virtual void urlDidChange(WebCore::Document*) OVERRIDE;
    4748    void setPermissionClient(WebPermissionClient* client) { m_client = client; }
    4849
    4950private:
     51    bool askIfIsEnabled(WebCore::Document*, WebCore::ContextFeatures::FeatureType, bool defaultValue);
     52
    5053    WebPermissionClient* m_client;
    5154};
Note: See TracChangeset for help on using the changeset viewer.