Changeset 50254 in webkit for trunk/JavaScriptCore/bytecompiler


Ignore:
Timestamp:
Oct 28, 2009, 6:25:02 PM (16 years ago)
Author:
[email protected]
Message:

Improve for..in enumeration performance
https://bugs.webkit.org/show_bug.cgi?id=30887

Reviewed by Geoff Garen.

Improve indexing of an object with a for..in iterator by
identifying cases where get_by_val is being used with a iterator
as the subscript and replace it with a new get_by_pname
bytecode. get_by_pname then optimizes lookups that directly access
the base object.

Location:
trunk/JavaScriptCore/bytecompiler
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp

    r49734 r50254  
    12821282RegisterID* BytecodeGenerator::emitGetByVal(RegisterID* dst, RegisterID* base, RegisterID* property)
    12831283{
     1284    for (size_t i = m_forInContextStack.size(); i > 0; i--) {
     1285        ForInContext& context = m_forInContextStack[i - 1];
     1286        if (context.propertyRegister == property) {
     1287            emitOpcode(op_get_by_pname);
     1288            instructions().append(dst->index());
     1289            instructions().append(base->index());
     1290            instructions().append(property->index());
     1291            instructions().append(context.expectedSubscriptRegister->index());
     1292            instructions().append(context.iterRegister->index());
     1293            instructions().append(context.indexRegister->index());
     1294            return dst;
     1295        }
     1296    }
    12841297    emitOpcode(op_get_by_val);
    12851298    instructions().append(dst->index());
  • trunk/JavaScriptCore/bytecompiler/BytecodeGenerator.h

    r49734 r50254  
    6262    };
    6363
     64    struct ForInContext {
     65        RefPtr<RegisterID> expectedSubscriptRegister;
     66        RefPtr<RegisterID> iterRegister;
     67        RefPtr<RegisterID> indexRegister;
     68        RefPtr<RegisterID> propertyRegister;
     69    };
     70
    6471    class BytecodeGenerator : public FastAllocBase {
    6572    public:
     
    332339        void popFinallyContext();
    333340
     341        void pushOptimisedForIn(RegisterID* expectedBase, RegisterID* iter, RegisterID* index, RegisterID* propertyRegister)
     342        {
     343            ForInContext context = { expectedBase, iter, index, propertyRegister };
     344            m_forInContextStack.append(context);
     345        }
     346
     347        void popOptimisedForIn()
     348        {
     349            m_forInContextStack.removeLast();
     350        }
     351
    334352        LabelScope* breakTarget(const Identifier&);
    335353        LabelScope* continueTarget(const Identifier&);
     
    468486        Vector<ControlFlowContext> m_scopeContextStack;
    469487        Vector<SwitchInfo> m_switchContextStack;
     488        Vector<ForInContext> m_forInContextStack;
    470489
    471490        int m_nextGlobalIndex;
Note: See TracChangeset for help on using the changeset viewer.