Changeset 35309 in webkit for trunk/JavaScriptCore/VM/CodeBlock.h


Ignore:
Timestamp:
Jul 23, 2008, 5:49:46 PM (17 years ago)
Author:
[email protected]
Message:

Improve switch performance.

Reviewed by Geoff Garen and Sam Weinig.

Improve switch performance by converting to a hashmap based jump
table to avoid the sequence of dispatches that would otherwise be
needed. This results in a 9-19x performance win for string switches
based on ad hoc testing, and a 6x improvement for integer switch
statements. SunSpider reports a 1.2% progression.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/VM/CodeBlock.h

    r35245 r35309  
    6767    };
    6868
     69    typedef HashMap<RefPtr<UString::Rep>, int32_t> StringJumpTable;
     70    struct SimpleJumpTable {
     71        Vector<int32_t> branchOffsets;
     72        int32_t min;
     73        int32_t offsetForValue(int32_t value, int32_t defaultOffset);
     74        void add(int32_t key, int32_t offset) {
     75            if (!branchOffsets[key])
     76                branchOffsets[key] = offset;
     77        }
     78    };
     79
    6980    struct CodeBlock {
    7081        CodeBlock(ScopeNode* ownerNode_, CodeType codeType_, PassRefPtr<SourceProvider> source_, unsigned sourceOffset_)
     
    113124        Vector<LineInfo> lineInfo;
    114125
     126        Vector<SimpleJumpTable> immediateSwitchJumpTables;
     127        Vector<SimpleJumpTable> characterSwitchJumpTables;
     128        Vector<StringJumpTable> stringSwitchJumpTables;
     129
    115130    private:
    116131        void dump(ExecState*, const Vector<Instruction>::const_iterator& begin, Vector<Instruction>::const_iterator&) const;
Note: See TracChangeset for help on using the changeset viewer.