Ignore:
Timestamp:
Aug 26, 2009, 12:46:47 AM (16 years ago)
Author:
[email protected]
Message:

How many copies of the parameters do you need?
https://bugs.webkit.org/show_bug.cgi?id=28701

Reviewed by Darin Adler.

The function parameters in JSC get copied a lot - and unnecessarily so.

Originally this happened due to duplicating FunctionBodyNodes on recompilation,
though the problem has been exacerbated by copying the parameters from the
original function body onto the executable, then back onto the real body that
will be generated (this happens on every function). And this is all made worse
since the data structures in question are a little ugly - C style arrays of C++
objects containing ref counts, so they need a full copy-construct (rather than
a simple memcpy).

This can all be greatly simplified by just punting the parameters off into
their own ref-counted object, and forgoing all the copying.

~no performance change, possible slight progression.

  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::BytecodeGenerator):

  • bytecompiler/BytecodeGenerator.h:

(JSC::BytecodeGenerator::makeFunction):

  • parser/Nodes.cpp:

(JSC::FunctionParameters::FunctionParameters):
(JSC::FunctionBodyNode::FunctionBodyNode):
(JSC::FunctionBodyNode::finishParsing):

  • parser/Nodes.h:

(JSC::FunctionBodyNode::parameters):
(JSC::FunctionBodyNode::parameterCount):

  • runtime/Executable.cpp:

(JSC::FunctionExecutable::~FunctionExecutable):
(JSC::FunctionExecutable::compile):
(JSC::FunctionExecutable::reparseExceptionInfo):
(JSC::FunctionExecutable::fromGlobalCode):
(JSC::FunctionExecutable::paramString):

  • runtime/Executable.h:

(JSC::FunctionExecutable::FunctionExecutable):
(JSC::FunctionExecutable::parameterCount):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/Executable.cpp

    r47738 r47775  
    5757FunctionExecutable::~FunctionExecutable()
    5858{
    59     for (int i = 0; i < m_parameterCount; ++i)
    60         m_parameters[i].~Identifier();
    61     fastFree(m_parameters);
    6259    delete m_codeBlock;
    6360}
     
    121118    if (m_forceUsesArguments)
    122119        body->setUsesArguments();
    123     body->finishParsing(copyParameters(), m_parameterCount, m_name);
     120    body->finishParsing(m_parameters, m_name);
    124121    recordParse(body->features(), body->lineNo(), body->lastLine());
    125122
     
    186183    if (m_forceUsesArguments)
    187184        newFunctionBody->setUsesArguments();
    188     newFunctionBody->finishParsing(copyParameters(), m_parameterCount, m_name);
     185    newFunctionBody->finishParsing(m_parameters, m_name);
    189186
    190187    ScopeChain scopeChain(scopeChainNode);
     
    263260    FunctionBodyNode* body = static_cast<FuncExprNode*>(funcExpr)->body();
    264261    ASSERT(body);
    265     return adoptRef(new FunctionExecutable(functionName, body->source(), body->usesArguments(), body->copyParameters(), body->parameterCount(), body->lineNo(), body->lastLine()));
    266 }
    267 
    268 Identifier* FunctionExecutable::copyParameters()
    269 {
    270     // This code uses the internal vector copier to make copy-constructed copies of the data in the array
    271     // (the array contains Identfiers which reference count Ustring::Reps, which must be ref'ed correctly).
    272     Identifier* parameters = static_cast<Identifier*>(fastMalloc(m_parameterCount * sizeof(Identifier)));
    273     WTF::VectorCopier<false, Identifier>::uninitializedCopy(m_parameters, m_parameters + m_parameterCount, parameters);
    274     return parameters;
     262    return FunctionExecutable::create(functionName, body->source(), body->usesArguments(), body->parameters(), body->lineNo(), body->lastLine());
    275263}
    276264
    277265UString FunctionExecutable::paramString() const
    278266{
     267    FunctionParameters& parameters = *m_parameters;
    279268    UString s("");
    280     for (int pos = 0; pos < m_parameterCount; ++pos) {
     269    for (size_t pos = 0; pos < parameters.size(); ++pos) {
    281270        if (!s.isEmpty())
    282271            s += ", ";
    283         s += m_parameters[pos].ustring();
     272        s += parameters[pos].ustring();
    284273    }
    285274
Note: See TracChangeset for help on using the changeset viewer.