Ignore:
Timestamp:
Nov 3, 2015, 10:48:45 AM (10 years ago)
Author:
[email protected]
Message:

B3/Air should use bubble sort for their insertion sets, because it's faster than std::stable_sort
https://bugs.webkit.org/show_bug.cgi?id=150828

Reviewed by Geoffrey Garen.

Source/JavaScriptCore:

Undo the 2% compile time regression caused by http://trac.webkit.org/changeset/191913.

  • b3/B3InsertionSet.cpp:

(JSC::B3::InsertionSet::execute): Switch to bubble sort.

  • b3/air/AirInsertionSet.cpp:

(JSC::B3::Air::InsertionSet::execute): Switch to bubble sort.

  • dfg/DFGBlockInsertionSet.cpp:

(JSC::DFG::BlockInsertionSet::execute): Switch back to quicksort.

Source/WTF:

Add a pretty good bubble sort implementation to WTF. This implementation has three
common tricks:

  • Forward and backward scans. This reduces the severity of certain kinds of bubble sort pathologies.
  • Return if a scan finds the list to be sorted. This gives the algorithm one of its most attractive properties: it's super fast when the list is already sorted.
  • Each scan eliminates one element from future scans. This makes the algorithm no worse than insertion sort.

Why do we want this? Because bubble sort is a really great stable sort for small lists,
or large lists in which only a handful of elements are out of order. Compiler insertion
sets tend to be one of those or somewhere in between: usually they are very small, and
usually they are sorted. It's rare that an element will be out of order, and when it is,
it's usually very close to where it's supposed to be.

This is a significant speed-up for B3 compile times.

  • WTF.xcodeproj/project.pbxproj:
  • wtf/BubbleSort.h: Added.

(WTF::bubbleSort):

  • wtf/CMakeLists.txt:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/dfg/DFGBlockInsertionSet.cpp

    r191913 r191960  
    7272        return false;
    7373   
    74     // We allow insertions to be given to us in any order. So, we need to
    75     // sort them before running WTF::executeInsertions.
    76     std::stable_sort(m_insertions.begin(), m_insertions.end());
     74    // We allow insertions to be given to us in any order. So, we need to sort them before
     75    // running WTF::executeInsertions. Also, we don't really care if the sort is stable since
     76    // basic block order doesn't have semantics - it's just to make code easier to read.
     77    std::sort(m_insertions.begin(), m_insertions.end());
    7778
    7879    executeInsertions(m_graph.m_blocks, m_insertions);
Note: See TracChangeset for help on using the changeset viewer.