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.h

    r47738 r47775  
    222222        friend class JIT;
    223223    public:
    224         FunctionExecutable(const Identifier& name, const SourceCode& source, bool forceUsesArguments, Identifier* parameters, int parameterCount, int firstLine, int lastLine)
    225             : ScriptExecutable(source)
    226             , m_forceUsesArguments(forceUsesArguments)
    227             , m_parameters(parameters)
    228             , m_parameterCount(parameterCount)
    229             , m_codeBlock(0)
    230             , m_name(name)
    231             , m_numVariables(0)
    232         {
    233             m_firstLine = firstLine;
    234             m_lastLine = lastLine;
     224        static PassRefPtr<FunctionExecutable> create(const Identifier& name, const SourceCode& source, bool forceUsesArguments, FunctionParameters* parameters, int firstLine, int lastLine)
     225        {
     226            return adoptRef(new FunctionExecutable(name, source, forceUsesArguments, parameters, firstLine, lastLine));
    235227        }
    236228
     
    262254
    263255        const Identifier& name() { return m_name; }
    264         size_t parameterCount() const { return m_parameterCount; }
     256        size_t parameterCount() const { return m_parameters->size(); }
    265257        size_t variableCount() const { return m_numVariables; }
    266258        UString paramString() const;
     
    272264
    273265    private:
     266        FunctionExecutable(const Identifier& name, const SourceCode& source, bool forceUsesArguments, FunctionParameters* parameters, int firstLine, int lastLine)
     267            : ScriptExecutable(source)
     268            , m_forceUsesArguments(forceUsesArguments)
     269            , m_parameters(parameters)
     270            , m_codeBlock(0)
     271            , m_name(name)
     272            , m_numVariables(0)
     273        {
     274            m_firstLine = firstLine;
     275            m_lastLine = lastLine;
     276        }
     277
    274278        void compile(ExecState*, ScopeChainNode*);
    275         Identifier* copyParameters();
    276279
    277280        bool m_forceUsesArguments;
    278         Identifier* m_parameters;
    279         int m_parameterCount;
     281        RefPtr<FunctionParameters> m_parameters;
    280282        CodeBlock* m_codeBlock;
    281283        Identifier m_name;
Note: See TracChangeset for help on using the changeset viewer.