@@ -894,21 +894,37 @@ class sema
894
894
// and is in the same function
895
895
using I = stable_vector<symbol>::const_iterator;
896
896
auto advance = [](I& i, int n, I bound) { // TODO Use `std::ranges::advance`
897
- CPP2_SCOPE_TIMER (" get_declaration_of_new - phase 2a 'advance' part of loop" );
897
+ // CPP2_SCOPE_TIMER("get_declaration_of_new - phase 2a 'advance' part of loop");
898
898
auto in = i;
899
899
if (std::abs (n) >= std::abs (bound - i)) {
900
900
i = bound;
901
901
}
902
902
else {
903
- CPP2_SCOPE_TIMER (" get_declaration_of_new - phase 2aa 'std::advance' specifically" );
903
+ // CPP2_SCOPE_TIMER("get_declaration_of_new - phase 2aa 'std::advance' specifically");
904
904
std::advance (i, n);
905
905
}
906
906
return n - (i - in);
907
907
};
908
908
advance (i, -int (i->position () > t.position ()), symbols.cbegin ());
909
909
advance (i, 1 , symbols.cend ());
910
- while (advance (i, -1 , symbols.begin ()) == 0 )
910
+
911
+ // --- PERFORMANCE NOTE ---
912
+ // In this hot function, this is a hot loop, and changing this lambda call...
913
+ //
914
+ // while (advance(i, -1, symbols.begin()) == 0)
915
+ // {
916
+ //
917
+ // ... to this instead...
918
+ //
919
+ while (i != symbols.begin ())
911
920
{
921
+ --i;
922
+ //
923
+ // ... is a 25% performance improvement on this entire loop in the `pure2-last-use.cpp2`
924
+ // test code. That's unexpected, so documenting it so we don't inadvertently change it
925
+ // back to `advance` "for consistency" with the previous lines.
926
+ // --- END PERFORMANCE NOTE ---
927
+
912
928
if (
913
929
i->sym .index () == symbol::active::declaration
914
930
&& i->depth <= depth
@@ -942,7 +958,7 @@ class sema
942
958
return &decl;
943
959
}
944
960
945
- CPP2_SCOPE_TIMER (" get_declaration_of_new - phase 2b 'move this' part of loop" );
961
+ // CPP2_SCOPE_TIMER("get_declaration_of_new - phase 2b 'move this' part of loop");
946
962
947
963
// If we reached a 'move this' parameter, look it up in the type members
948
964
if (
0 commit comments