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/parser/Nodes.cpp

    r47738 r47775  
    19811981// ------------------------------ FunctionBodyNode -----------------------------
    19821982
     1983FunctionParameters::FunctionParameters(ParameterNode* firstParameter)
     1984{
     1985    for (ParameterNode* parameter = firstParameter; parameter; parameter = parameter->nextParam())
     1986        append(parameter->ident());
     1987}
     1988
    19831989inline FunctionBodyNode::FunctionBodyNode(JSGlobalData* globalData)
    19841990    : ScopeNode(globalData)
    1985     , m_parameters(0)
    1986     , m_parameterCount(0)
    19871991{
    19881992}
     
    19901994inline FunctionBodyNode::FunctionBodyNode(JSGlobalData* globalData, SourceElements* children, VarStack* varStack, FunctionStack* funcStack, const SourceCode& sourceCode, CodeFeatures features, int numConstants)
    19911995    : ScopeNode(globalData, sourceCode, children, varStack, funcStack, features, numConstants)
    1992     , m_parameters(0)
    1993     , m_parameterCount(0)
    1994 {
    1995 }
    1996 
    1997 FunctionBodyNode::~FunctionBodyNode()
    1998 {
    1999     for (size_t i = 0; i < m_parameterCount; ++i)
    2000         m_parameters[i].~Identifier();
    2001     fastFree(m_parameters);
     1996{
    20021997}
    20031998
    20041999void FunctionBodyNode::finishParsing(const SourceCode& source, ParameterNode* firstParameter, const Identifier& ident)
    20052000{
    2006     Vector<Identifier> parameters;
    2007     for (ParameterNode* parameter = firstParameter; parameter; parameter = parameter->nextParam())
    2008         parameters.append(parameter->ident());
    2009     size_t count = parameters.size();
    2010 
    20112001    setSource(source);
    2012     finishParsing(parameters.releaseBuffer(), count, ident);
    2013 }
    2014 
    2015 void FunctionBodyNode::finishParsing(Identifier* parameters, size_t parameterCount, const Identifier& ident)
     2002    finishParsing(FunctionParameters::create(firstParameter), ident);
     2003}
     2004
     2005void FunctionBodyNode::finishParsing(PassRefPtr<FunctionParameters> parameters, const Identifier& ident)
    20162006{
    20172007    ASSERT(!source().isNull());
    20182008    m_parameters = parameters;
    2019     m_parameterCount = parameterCount;
    20202009    m_ident = ident;
    20212010}
     
    20542043}
    20552044
    2056 Identifier* FunctionBodyNode::copyParameters()
    2057 {
    2058     Identifier* parameters = static_cast<Identifier*>(fastMalloc(m_parameterCount * sizeof(Identifier)));
    2059     VectorCopier<false, Identifier>::uninitializedCopy(m_parameters, m_parameters + m_parameterCount, parameters);
    2060     return parameters;
    2061 }
    2062 
    20632045// ------------------------------ FuncDeclNode ---------------------------------
    20642046
Note: See TracChangeset for help on using the changeset viewer.