Index: src/ResolvExpr/TypeEnvironment.cc
===================================================================
--- src/ResolvExpr/TypeEnvironment.cc	(revision 04273e9e7c52353f38bcd37e425ecf90e764d3e0)
+++ src/ResolvExpr/TypeEnvironment.cc	(revision 03da5119382527d15bc759490fa53866dd7c35e4)
@@ -5,5 +5,5 @@
 // file "LICENCE" distributed with Cforall.
 //
-// TypeEnvironment.cc -- 
+// TypeEnvironment.cc --
 //
 // Author           : Richard C. Bilson
@@ -23,4 +23,53 @@
 
 namespace ResolvExpr {
+	// adding this comparison operator significantly improves assertion resolution run time for
+	// some cases. The current resolution algorithm's speed partially depends on the order of
+	// assertions. Assertions which have fewer possible matches should appear before
+	// assertions which have more possible matches. This seems to imply that this could
+	// be further improved by providing an indexer as an additional argument and ordering based
+	// on the number of matches of the same kind (object, function) for the names of the
+	// declarations.
+	//
+	// I've seen a TU go from 54 minutes to 1 minute 34 seconds with the addition of this comparator.
+	bool AssertCompare::operator()( DeclarationWithType * d1, DeclarationWithType * d2 ) {
+			// Objects are always less than functions
+			if ( ObjectDecl * objectDecl1 = dynamic_cast< ObjectDecl * >( d1 ) ) {
+				if ( ObjectDecl * objectDecl2 = dynamic_cast< ObjectDecl * >( d2 ) ) {
+					// objects are ordered by name then type pointer, in that order
+					int cmp = objectDecl1->get_name().compare( objectDecl2->get_name() );
+					return cmp < 0 ||
+						( cmp == 0 && objectDecl1->get_type() < objectDecl2->get_type() );
+				} else {
+					return true;
+				}
+			} else if ( FunctionDecl * funcDecl1 = dynamic_cast< FunctionDecl * >( d1 ) ) {
+				if ( FunctionDecl * funcDecl2 = dynamic_cast< FunctionDecl * >( d2 ) ) {
+					// functions are ordered by name, # parameters, # returnVals, type pointer in that order
+					FunctionType * ftype1 = funcDecl1->get_functionType();
+					FunctionType * ftype2 = funcDecl2->get_functionType();
+					int numThings1 = ftype1->get_parameters().size() + ftype1->get_returnVals().size();
+					int numThings2 = ftype2->get_parameters().size() + ftype2->get_returnVals().size();
+					if ( numThings1 < numThings2 ) return true;
+					if ( numThings1 > numThings2 ) return false;
+
+					// if ( ftype1->get_parameters().size() < ftype2->get_parameters().size() ) return true;
+					// else if ( ftype1->get_parameters().size() > ftype2->get_parameters().size() ) return false;
+					// // same number of parameters
+					// if ( ftype1->get_returnVals().size() < ftype2->get_returnVals().size() ) return true;
+					// else if ( ftype1->get_returnVals().size() > ftype2->get_returnVals().size() ) return false;
+					// same number of return vals
+					// int cmp = funcDecl1->get_name().compare( funcDecl2->get_name() );
+					// if ( cmp < 0 ) return true;
+					// else if ( cmp > 0 ) return false;
+					// // same name
+					return ftype1 < ftype2;
+				} else {
+					return false;
+				}
+			} else {
+				assert( false );
+			}
+		}
+
 	void printAssertionSet( const AssertionSet &assertions, std::ostream &os, int indent ) {
 		for ( AssertionSet::const_iterator i = assertions.begin(); i != assertions.end(); ++i ) {
Index: src/ResolvExpr/TypeEnvironment.h
===================================================================
--- src/ResolvExpr/TypeEnvironment.h	(revision 04273e9e7c52353f38bcd37e425ecf90e764d3e0)
+++ src/ResolvExpr/TypeEnvironment.h	(revision 03da5119382527d15bc759490fa53866dd7c35e4)
@@ -5,5 +5,5 @@
 // file "LICENCE" distributed with Cforall.
 //
-// TypeEnvironment.h -- 
+// TypeEnvironment.h --
 //
 // Author           : Richard C. Bilson
@@ -28,5 +28,8 @@
 
 namespace ResolvExpr {
-	typedef std::map< DeclarationWithType*, bool > AssertionSet;
+	struct AssertCompare {
+		bool operator()( DeclarationWithType * d1, DeclarationWithType * d2 );
+	};
+	typedef std::map< DeclarationWithType*, bool, AssertCompare > AssertionSet;
 	typedef std::map< std::string, TypeDecl::Kind > OpenVarSet;
 
@@ -39,5 +42,5 @@
 		bool allowWidening;
 		TypeDecl::Kind kind;
-  
+
 		void initialize( const EqvClass &src, EqvClass &dest );
 		EqvClass();
@@ -62,5 +65,5 @@
 		void extractOpenVars( OpenVarSet &openVars ) const;
 		TypeEnvironment *clone() const { return new TypeEnvironment( *this ); }
-  
+
 		typedef std::list< EqvClass >::iterator iterator;
 		iterator begin() { return env.begin(); }
Index: src/ResolvExpr/Unify.cc
===================================================================
--- src/ResolvExpr/Unify.cc	(revision 04273e9e7c52353f38bcd37e425ecf90e764d3e0)
+++ src/ResolvExpr/Unify.cc	(revision 03da5119382527d15bc759490fa53866dd7c35e4)
@@ -484,13 +484,13 @@
 		FunctionType *otherFunction = dynamic_cast< FunctionType* >( type2 );
 		if ( otherFunction && functionType->get_isVarArgs() == otherFunction->get_isVarArgs() ) {
-
-			if ( unifyDeclList( functionType->get_parameters().begin(), functionType->get_parameters().end(), otherFunction->get_parameters().begin(), otherFunction->get_parameters().end(), env, needAssertions, haveAssertions, openVars, indexer ) ) {
-
-				if ( unifyDeclList( functionType->get_returnVals().begin(), functionType->get_returnVals().end(), otherFunction->get_returnVals().begin(), otherFunction->get_returnVals().end(), env, needAssertions, haveAssertions, openVars, indexer ) ) {
-
-					markAssertions( haveAssertions, needAssertions, functionType );
-					markAssertions( haveAssertions, needAssertions, otherFunction );
-
-					result = true;
+			if ( functionType->get_parameters().size() == otherFunction->get_parameters().size() && functionType->get_returnVals().size() == otherFunction->get_returnVals().size() ) {
+				if ( unifyDeclList( functionType->get_parameters().begin(), functionType->get_parameters().end(), otherFunction->get_parameters().begin(), otherFunction->get_parameters().end(), env, needAssertions, haveAssertions, openVars, indexer ) ) {
+					if ( unifyDeclList( functionType->get_returnVals().begin(), functionType->get_returnVals().end(), otherFunction->get_returnVals().begin(), otherFunction->get_returnVals().end(), env, needAssertions, haveAssertions, openVars, indexer ) ) {
+
+						markAssertions( haveAssertions, needAssertions, functionType );
+						markAssertions( haveAssertions, needAssertions, otherFunction );
+
+						result = true;
+					} // if
 				} // if
 			} // if
