diff --git a/GeoModelCore/GeoModelKernel/CMakeLists.txt b/GeoModelCore/GeoModelKernel/CMakeLists.txt
index f4242540e787a29c5d5b8b866b3de1079a479fbb..3cc3c71147a038106852cd000b778111ffb6a5fa 100644
--- a/GeoModelCore/GeoModelKernel/CMakeLists.txt
+++ b/GeoModelCore/GeoModelKernel/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
+# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
 
 # Find the header and source files.
 file( GLOB SOURCES src/*.cxx )
@@ -26,6 +26,7 @@ if ( "${CMAKE_BUILD_TYPE}" STREQUAL "Debug" )
   set_source_files_properties(
      ${CMAKE_CURRENT_SOURCE_DIR}/src/GeoXF.cxx
      ${CMAKE_CURRENT_SOURCE_DIR}/src/GeoAlignableTransform.cxx
+     ${CMAKE_CURRENT_SOURCE_DIR}/src/GeoShapeShift.cxx
      PROPERTIES
      COMPILE_FLAGS "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}"
      COMPILE_DEFINITIONS "FLATTEN" )
diff --git a/GeoModelCore/GeoModelKernel/src/GeoShapeShift.cxx b/GeoModelCore/GeoModelKernel/src/GeoShapeShift.cxx
index 373a804a164f3adf6f58ce21bab64750b50d501a..1d3c7306eb2974cd5b67fe0a68509c48a11fde48 100755
--- a/GeoModelCore/GeoModelKernel/src/GeoShapeShift.cxx
+++ b/GeoModelCore/GeoModelKernel/src/GeoShapeShift.cxx
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
 */
 
 #include "GeoModelKernel/GeoShapeShift.h"
@@ -53,6 +53,14 @@ void GeoShapeShift::extent (double& xmin, double& ymin, double& zmin,
   }
 }
 
+#if defined(FLATTEN) && defined(__GNUC__)
+// We compile this package with optimization, even in debug builds; otherwise,
+// the heavy use of Eigen makes it too slow.  However, from here we may call
+// to out-of-line Eigen code that is linked from other DSOs; in that case,
+// it would not be optimized.  Avoid this by forcing all Eigen code
+// to be inlined here if possible.
+__attribute__ ((flatten))
+#endif
 bool GeoShapeShift::contains (double x, double y, double z) const {
   const GeoShape* shape = getOp();
   const GeoTrf::Transform3D& trans = getX();