Avoid stripping typedefs too much
authorDodji Seketeli <dodji@redhat.com>
Tue, 8 Nov 2016 11:22:50 +0000 (12:22 +0100)
committerDodji Seketeli <dodji@redhat.com>
Thu, 10 Nov 2016 13:09:50 +0000 (14:09 +0100)
strip_typedef re-constructs entire type trees and canonicalize them.
Calling it a lot on very deep and recursive trees can be costly.

Unfortunately, categorization of changes uses strip_typedef quite a
bit to determine if the two types that are different are still
compatible.  When used on changesets generating from comparing two
Linux Kernels, it makes changes categorization dominate CPU usage
profiles.

This patch avoids using strip_typedef to determine if two types are
compatible and thus speeds up type categorization of changes involving
lots of deep and recursive type trees.

* src/abg-ir.cc (types_are_compatible)
(is_compatible_with_class_type): Do not strip typedefs.  Just get
their leaf types.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
src/abg-ir.cc

index 8b6c4cea867aa75155b9b6a892d112c4207b96f9..e52d2736d6931b07197ae71008355e86bc1a7ea5 100644 (file)
@@ -5470,8 +5470,21 @@ types_are_compatible(const type_base_sptr type1,
   if (!type1 || !type2)
     return false;
 
-  type_base_sptr t1 = strip_typedef(type1);
-  type_base_sptr t2 = strip_typedef(type2);
+  if (type1 == type2)
+    return true;
+
+  // Normally we should strip typedefs entirely, but this is
+  // potentially costly, especially on binaries with huge changesets
+  // like the Linux Kernel.  So we just get the leaf types for now.
+  //
+  // Maybe there should be an option by which users accepts to pay the
+  // CPU usage toll in exchange for finer filtering?
+
+  // type_base_sptr t1 = strip_typedef(type1);
+  // type_base_sptr t2 = strip_typedef(type2);
+
+  type_base_sptr t1 = peel_typedef_type(type1);
+  type_base_sptr t2 = peel_typedef_type(type2);
 
   return t1 == t2;
 }
@@ -5866,7 +5879,16 @@ is_compatible_with_class_type(const type_base_sptr& t)
 {
   if (!t)
     return class_decl_sptr();
-  type_base_sptr ty = strip_typedef(t);
+
+  // Normally we should strip typedefs entirely, but this is
+  // potentially costly, especially on binaries with huge changesets
+  // like the Linux Kernel.  So we just get the leaf types for now.
+  //
+  // Maybe there should be an option by which users accepts to pay the
+  // CPU usage toll in exchange for finer filtering?
+
+  // type_base_sptr ty = strip_typedef(t);
+  type_base_sptr ty = peel_typedef_type(t);;
   return is_class_type(ty);
 }