]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++/modules: disable dependent ADL inside header unit [PR125334]
authorPatrick Palka <ppalka@redhat.com>
Fri, 5 Jun 2026 21:05:33 +0000 (17:05 -0400)
committerPatrick Palka <ppalka@redhat.com>
Fri, 5 Jun 2026 21:05:33 +0000 (17:05 -0400)
This PR reports that building <bits/stdc++.h> as a header unit later
slows down initial std module stream-in by around 2x compared to if
the std module is built without the header unit, i.e.

  g++ -fmodules -fsearch-include-path bits/std.cc
  g++ -fmodules testcase.C # 15% slower vs before r16-6311

vs

  g++ -fmodules -fsearch-include-path bits/stdc++.h bits/std.cc
  g++ -fmodules testcase.C # 100% slower vs before r16-6311

This happens after the dependent ADL patch r16-6311.  My initial theory
for the slowdown was that the ADL step adds in many more dependency edges
between entities and results in larger SCC clusters, making lazy loading
less lazy, but the number of overall clusters doesn't seem to significantly
before/after the patch.  So I have no idea why there's such a big slowdown
and why header units are affected more.

But my basic understanding of the dependent ADL part of reachability
analysis is that it's not really needed when building a header unit
because header units don't discard or hide any entities.

So this patch disables it for header units which restores std module
stream-in back to pre r16-6311 levels when <bits/stdc++.h> is built as a
header unit.  When built without the header unit then std module stream-in
is still about 15% slower.  Maybe there's ways to safely speed up that
case too (e.g. only add dependency edges to GMF entities?) but I'll
leave that as future work.

PR c++/125334

gcc/cp/ChangeLog:

* module.cc (depset::hash::add_dependent_adl_entities):
Disable when inside a header unit.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/module.cc

index 223ab33d54542f184ef6340ca3db3a8d1aaba730..d81db520bab839177677ff5b6e4ee0939686f85f 100644 (file)
@@ -15254,6 +15254,12 @@ void
 depset::hash::add_dependent_adl_entities (tree expr)
 {
   gcc_checking_assert (!is_key_order ());
+
+  /* This is not needed for header units where everything is
+     visible to name lookup, nothing is discarded.  */
+  if (header_module_p ())
+    return;
+
   if (TREE_CODE (current->get_entity ()) != TEMPLATE_DECL)
     return;