Skip to content
  • oliver@apple.com's avatar
    fourthTier: DFG should optimize identifier string equality · bd15be8f
    oliver@apple.com authored
    https://bugs.webkit.org/show_bug.cgi?id=117920
    
    Source/JavaScriptCore:
    
    Reviewed by Sam Weinig.
    
    This is a 20% speed-up for string equality comparisons when both strings are
    identifiers.
    
    This is important for two reasons:
    
    1) Using strings as enumerations is an idiom. A great example is typeof. It
       would be great if this performed better.
    
    2) When I implement switch_string in the DFG, it would be great to optimize
       the case where the switched-on value is an identifier. That would involve
       a simple binary switch rather than a more complicated trie-switch over
       characters.
    
    * bytecode/SpeculatedType.cpp:
    (JSC::dumpSpeculation):
    (JSC::speculationToAbbreviatedString):
    (JSC::speculationFromCell):
    * bytecode/SpeculatedType.h:
    (JSC):
    (JSC::isStringIdentSpeculation):
    (JSC::isStringSpeculation):
    * dfg/DFGAbstractState.cpp:
    (JSC::DFG::AbstractState::executeEffects):
    * dfg/DFGFixupPhase.cpp:
    (JSC::DFG::FixupPhase::fixupNode):
    * dfg/DFGNode.h:
    (JSC::DFG::Node::shouldSpeculateStringIdent):
    (Node):
    * dfg/DFGSpeculativeJIT.cpp:
    (JSC::DFG::SpeculativeJIT::compilePeepHoleBranch):
    (JSC::DFG::SpeculativeJIT::compare):
    (JSC::DFG::SpeculativeJIT::compileStrictEq):
    (JSC::DFG::SpeculativeJIT::compileStringEquality):
    (JSC::DFG::SpeculativeJIT::compileStringIdentEquality):
    (DFG):
    (JSC::DFG::SpeculativeJIT::speculateString):
    (JSC::DFG::SpeculativeJIT::speculateStringIdentAndLoadStorage):
    (JSC::DFG::SpeculativeJIT::speculateStringIdent):
    (JSC::DFG::SpeculativeJIT::speculate):
    * dfg/DFGSpeculativeJIT.h:
    (SpeculativeJIT):
    * dfg/DFGUseKind.cpp:
    (WTF::printInternal):
    * dfg/DFGUseKind.h:
    (JSC::DFG::typeFilterFor):
    (JSC::DFG::isCell):
    
    LayoutTests:
    
    Reviewed by Sam Weinig.
    
    Add a benchmark for string equality where there is a long identifier, and
    also add a benchmark for non-identifier string equality (since the previous
    test for string equality was really identifier equality).
    
    * fast/js/regress/script-tests/string-long-ident-equality.js: Added.
    (foo):
    * fast/js/regress/script-tests/string-var-equality.js: Added.
    (addFoo):
    (foo):
    * fast/js/regress/string-long-ident-equality-expected.txt: Added.
    * fast/js/regress/string-long-ident-equality.html: Added.
    * fast/js/regress/string-var-equality-expected.txt: Added.
    * fast/js/regress/string-var-equality.html: Added.
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@153245 268f45cc-cd09-0410-ab3c-d52691b4dbfc
    bd15be8f