Ignore:
Timestamp:
Dec 13, 2015, 12:03:24 PM (9 years ago)
Author:
[email protected]
Message:

CachedScript could have a copy-free path for all-ASCII scripts.
<https://webkit.org/b/152203>

Source/JavaScriptCore:

Reviewed by Antti Koivisto.

Make SourceProvider vend a StringView instead of a String.
This relaxes the promises that providers have to make about string lifetimes.

This means that on the WebCore side, CachedScript is free to cache a String
internally, while only ever exposing it as a temporary StringView.

A few extra copies (CPU, not memory) are introduced, none of them on hot paths.

  • API/JSScriptRef.cpp:
  • bytecode/CodeBlock.cpp:

(JSC::CodeBlock::sourceCodeForTools):
(JSC::CodeBlock::dumpSource):

  • inspector/ScriptDebugServer.cpp:

(Inspector::ScriptDebugServer::dispatchDidParseSource):
(Inspector::ScriptDebugServer::dispatchFailedToParseSource):

  • interpreter/Interpreter.cpp:

(JSC::Interpreter::execute):

  • jsc.cpp:

(functionFindTypeForExpression):
(functionHasBasicBlockExecuted):
(functionBasicBlockExecutionCount):

  • parser/Lexer.cpp:

(JSC::Lexer<T>::setCode):

  • parser/Lexer.h:

(JSC::Lexer<LChar>::setCodeStart):
(JSC::Lexer<UChar>::setCodeStart):

  • parser/Parser.h:

(JSC::Parser::getToken):

  • parser/SourceCode.cpp:

(JSC::SourceCode::toUTF8):

  • parser/SourceCode.h:

(JSC::SourceCode::hash):
(JSC::SourceCode::view):
(JSC::SourceCode::toString): Deleted.

  • parser/SourceCodeKey.h:

(JSC::SourceCodeKey::SourceCodeKey):
(JSC::SourceCodeKey::string):

  • parser/SourceProvider.h:

(JSC::SourceProvider::getRange):

  • runtime/Completion.cpp:

(JSC::loadAndEvaluateModule):
(JSC::loadModule):

  • runtime/ErrorInstance.cpp:

(JSC::appendSourceToError):

  • runtime/FunctionPrototype.cpp:

(JSC::functionProtoFuncToString):

  • tools/FunctionOverrides.cpp:

(JSC::initializeOverrideInfo):
(JSC::FunctionOverrides::initializeOverrideFor):

Source/WebCore:

Reviewed by ANtti Koivisto.

Many (if not most) of script resources on the web contain nothing but ASCII characters.
Such resources, when streamed through a text decoder, will yield the exact same byte
sequence, except in anonymous heap memory instead of delicious file-backed pages.

Care is taken to ensure that the wrapper StringImpl is updated to target newly cached
resource data if an asynchronous caching notification comes in.

  • loader/cache/CachedResource.cpp:

(WebCore::CachedResource::tryReplaceEncodedData):

  • loader/cache/CachedResource.h:

(WebCore::CachedResource::didReplaceSharedBufferContents):

  • loader/cache/CachedScript.cpp:

(WebCore::encodingMayBeAllASCII):
(WebCore::CachedScript::script):
(WebCore::CachedScript::didReplaceSharedBufferContents):

  • loader/cache/CachedScript.h:
  • platform/SharedBuffer.h:
  • platform/cf/SharedBufferCF.cpp:

(WebCore::SharedBuffer::tryReplaceContentsWithPlatformBuffer):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/parser/SourceCode.cpp

    r163844 r194017  
    3737        return CString("", 0);
    3838   
    39     return m_provider->source().impl()->utf8ForRange(m_startChar, m_endChar - m_startChar);
     39    return m_provider->source().substring(m_startChar, m_endChar - m_startChar).utf8();
    4040}
    4141
Note: See TracChangeset for help on using the changeset viewer.