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/b3/B3InsertionSet.cpp

    r191913 r191960  
    3030
    3131#include "B3BasicBlock.h"
     32#include <wtf/BubbleSort.h>
    3233
    3334namespace JSC { namespace B3 {
     
    3536void InsertionSet::execute(BasicBlock* block)
    3637{
    37     std::stable_sort(m_insertions.begin(), m_insertions.end());
     38    bubbleSort(m_insertions.begin(), m_insertions.end());
    3839    executeInsertions(block->m_values, m_insertions);
    3940}
Note: See TracChangeset for help on using the changeset viewer.