Changeset 60684 in webkit


Ignore:
Timestamp:
Jun 4, 2010 9:59:23 AM (14 years ago)
Author:
eric@webkit.org
Message:

2010-06-04 Tony Gentilcore <tonyg@chromium.org>

Reviewed by Adam Barth.

Persist V8's ScriptData to the memory cache.
https://bugs.webkit.org/show_bug.cgi?id=38661

This stores V8's ScriptData in the memory cache and also causes the
network platform layer to be notified of the available cacheable
metadata.

Chromium's morejs benchmark shows a 3-4% improvement on fast hardware.

No new tests because no new functionality.

  • bindings/v8/ScriptSourceCode.h: (WebCore::ScriptSourceCode::ScriptSourceCode): (WebCore::ScriptSourceCode::cachedScript):
  • bindings/v8/V8Proxy.cpp: (WebCore::V8Proxy::compileScript): (WebCore::V8Proxy::precompileScript): (WebCore::V8Proxy::evaluate):
  • bindings/v8/V8Proxy.h:
Location:
trunk/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r60683 r60684  
     12010-06-04  Tony Gentilcore  <tonyg@chromium.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        Persist V8's ScriptData to the memory cache.
     6        https://bugs.webkit.org/show_bug.cgi?id=38661
     7
     8        This stores V8's ScriptData in the memory cache and also causes the
     9        network platform layer to be notified of the available cacheable
     10        metadata.
     11
     12        Chromium's morejs benchmark shows a 3-4% improvement on fast hardware.
     13
     14        No new tests because no new functionality.
     15
     16        * bindings/v8/ScriptSourceCode.h:
     17        (WebCore::ScriptSourceCode::ScriptSourceCode):
     18        (WebCore::ScriptSourceCode::cachedScript):
     19        * bindings/v8/V8Proxy.cpp:
     20        (WebCore::V8Proxy::compileScript):
     21        (WebCore::V8Proxy::precompileScript):
     22        (WebCore::V8Proxy::evaluate):
     23        * bindings/v8/V8Proxy.h:
     24
    1252010-06-04  Tony Gentilcore  <tonyg@chromium.org>
    226
  • trunk/WebCore/bindings/v8/ScriptSourceCode.h

    r47912 r60684  
    3232#define ScriptSourceCode_h
    3333
     34#include "CachedResourceHandle.h"
    3435#include "CachedScript.h"
    3536#include "KURL.h"
     
    4243    ScriptSourceCode(const String& source, const KURL& url = KURL(), int startLine = 1)
    4344        : m_source(source)
     45        , m_cachedScript(0)
    4446        , m_url(url)
    4547        , m_startLine(startLine)
     
    5153    ScriptSourceCode(CachedScript* cs)
    5254        : m_source(cs->script())
     55        , m_cachedScript(cs)
    5356        , m_url(ParsedURLString, cs->url())
    5457        , m_startLine(1)
     
    5962
    6063    const String& source() const { return m_source; }
     64    CachedScript* cachedScript() const { return m_cachedScript.get(); }
    6165    const KURL& url() const { return m_url; }
    6266    int startLine() const { return m_startLine; }
     
    6468private:
    6569    String m_source;
     70    CachedResourceHandle<CachedScript> m_cachedScript;
    6671    KURL m_url;
    6772    int m_startLine;
  • trunk/WebCore/bindings/v8/V8Proxy.cpp

    r58345 r60684  
    3232#include "V8Proxy.h"
    3333
     34#include "CachedMetadata.h"
    3435#include "CSSMutableStyleDeclaration.h"
    3536#include "DateExtension.h"
     
    7172#include <wtf/Assertions.h>
    7273#include <wtf/OwnArrayPtr.h>
     74#include <wtf/OwnPtr.h>
    7375#include <wtf/StdLibExtras.h>
    7476#include <wtf/StringExtras.h>
     
    234236}
    235237
    236 v8::Handle<v8::Script> V8Proxy::compileScript(v8::Handle<v8::String> code, const String& fileName, int baseLine)
     238v8::Handle<v8::Script> V8Proxy::compileScript(v8::Handle<v8::String> code, const String& fileName, int baseLine, v8::ScriptData* scriptData)
    237239{
    238240    const uint16_t* fileNameString = fromWebCoreString(fileName);
     
    240242    v8::Handle<v8::Integer> line = v8::Integer::New(baseLine);
    241243    v8::ScriptOrigin origin(name, line);
    242     v8::Handle<v8::Script> script = v8::Script::Compile(code, &origin);
     244    v8::Handle<v8::Script> script = v8::Script::Compile(code, &origin, scriptData);
    243245    return script;
    244246}
     
    339341}
    340342
     343PassOwnPtr<v8::ScriptData> V8Proxy::precompileScript(const ScriptSourceCode& source)
     344{
     345    // A pseudo-randomly chosen ID used to store and retrieve V8 ScriptData from
     346    // the CachedScript. If the format changes, this ID should be changed too.
     347    static const unsigned dataTypeID = 0xECC13BD7;
     348
     349    // Very small scripts are not worth the effort to preparse.
     350    static const unsigned minPreparseLength = 1024;
     351
     352    CachedScript* cachedScript = source.cachedScript();
     353    if (!cachedScript)
     354        return 0;
     355
     356    CachedMetadata* cachedMetadata = cachedScript->cachedMetadata(dataTypeID);
     357    if (cachedMetadata)
     358        return v8::ScriptData::New(cachedMetadata->data(), cachedMetadata->size());
     359
     360    const CString& utf8Source = source.source().utf8();
     361    if (utf8Source.length() < minPreparseLength)
     362        return 0;
     363
     364    v8::ScriptData* scriptData = v8::ScriptData::PreCompile(utf8Source.data(), utf8Source.length());
     365    cachedScript->setCachedMetadata(dataTypeID, scriptData->Data(), scriptData->Length());
     366
     367    return scriptData;
     368}
     369
    341370v8::Local<v8::Value> V8Proxy::evaluate(const ScriptSourceCode& source, Node* node)
    342371{
     
    364393        PlatformBridge::traceEventBegin("v8.compile", node, "");
    365394#endif
     395        OwnPtr<v8::ScriptData> scriptData = precompileScript(source);
    366396
    367397        // NOTE: For compatibility with WebCore, ScriptSourceCode's line starts at
    368398        // 1, whereas v8 starts at 0.
    369         v8::Handle<v8::Script> script = compileScript(code, source.url(), source.startLine() - 1);
     399        v8::Handle<v8::Script> script = compileScript(code, source.url(), source.startLine() - 1, scriptData.get());
    370400#if PLATFORM(CHROMIUM)
    371401        PlatformBridge::traceEventEnd("v8.compile", node, "");
  • trunk/WebCore/bindings/v8/V8Proxy.h

    r58919 r60684  
    286286        static v8::Handle<v8::Value> checkNewLegal(const v8::Arguments&);
    287287
    288         static v8::Handle<v8::Script> compileScript(v8::Handle<v8::String> code, const String& fileName, int baseLine);
     288        static v8::Handle<v8::Script> compileScript(v8::Handle<v8::String> code, const String& fileName, int baseLine, v8::ScriptData* scriptData = 0);
    289289
    290290        // If the exception code is different from zero, a DOM exception is
     
    338338        void resetIsolatedWorlds();
    339339
     340        PassOwnPtr<v8::ScriptData> precompileScript(const ScriptSourceCode& source);
     341
    340342        // Returns false when we're out of memory in V8.
    341343        bool setInjectedScriptContextDebugId(v8::Handle<v8::Context> targetContext);
Note: See TracChangeset for help on using the changeset viewer.