[Webkit-unassigned] [Bug 52622] Cache function offsets to speed up javascript parsing

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Tue Jan 18 09:23:41 PST 2011


https://bugs.webkit.org/show_bug.cgi?id=52622





--- Comment #2 from Oliver Hunt <oliver at apple.com>  2011-01-18 09:23:40 PST ---
(From update of attachment 79268)
View in context: https://bugs.webkit.org/attachment.cgi?id=79268&action=review

> Source/JavaScriptCore/parser/JSParser.cpp:121
> +    struct CachedFunctionInfo : public SourceProvider::CachedSourceInfo {
> +        CachedFunctionInfo(JSToken closeBraceToken)
> +            : closeBraceToken(closeBraceToken) 
> +        {
> +        }
> +        unsigned approximateByteSize() const
> +        {
> +            static const unsigned assummedAverageIdentifierSize = 20;
> +            unsigned size = sizeof(*this);
> +            size += declaredVariables.size() * assummedAverageIdentifierSize;
> +            size += usedVariables.size() * assummedAverageIdentifierSize;
> +            size += closedVariables.size() * assummedAverageIdentifierSize;
> +            size += writtenVariables.size() * assummedAverageIdentifierSize;
> +            return size;
> +        }
> +
> +        JSToken closeBraceToken;
> +        bool usesEval;
> +        Vector<RefPtr<StringImpl> > declaredVariables;
> +        Vector<RefPtr<StringImpl> > usedVariables;
> +        Vector<RefPtr<StringImpl> > closedVariables;
> +        Vector<RefPtr<StringImpl> > writtenVariables;
> +    };

The cached info doesn't need to store a functions declared or closed variables.  All it should need to store is the used and written free variables which is basically usedVariables - declaredVariables and writtenVariables - declaredVariables.

Rather than storing the entirety of the close brace token you should be able to simply store the start character and line number.

> Source/JavaScriptCore/parser/JSParser.cpp:1326
> +    if (CachedFunctionInfo* cachedInfo = findCachedFunctionInfo(openBracePos)) {
> +        // If we know about this function already, we can use the cached info and skip the parser to the end of the function.
> +        body = context.createFunctionBody(strictMode());
> +
> +        functionScope->restoreFunctionInfo(cachedInfo);
> +        failIfFalse(popScope(functionScope, TreeBuilder::NeedsFreeVariableInfo));
> +
> +        m_token = cachedInfo->closeBraceToken;
> +        m_lexer->setOffsetAfterCloseBraceToken(m_token);
> +        closeBracePos = m_token.m_info.startOffset;
> +
> +        next();
> +        return true;
> +    }

The ability to use the cache is should be determined by the type of treebuilder being used -- something like  TreeBuilder::CanUseFunctionCache will be fine.

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the webkit-unassigned mailing list