diff --git a/Tracking/TrkDetDescr/TrkSurfaces/CMakeLists.txt b/Tracking/TrkDetDescr/TrkSurfaces/CMakeLists.txt
index fbbd490e5ed2b3479ed2f3937c8c754ff51e56cf..b35386df9a9457b480cc14a362f1283ce2a510ba 100644
--- a/Tracking/TrkDetDescr/TrkSurfaces/CMakeLists.txt
+++ b/Tracking/TrkDetDescr/TrkSurfaces/CMakeLists.txt
@@ -20,6 +20,7 @@ if ( "${CMAKE_BUILD_TYPE}" STREQUAL "Debug" )
      ${CMAKE_CURRENT_SOURCE_DIR}/src/PlaneSurface.cxx
      ${CMAKE_CURRENT_SOURCE_DIR}/src/CylinderSurface.cxx
      ${CMAKE_CURRENT_SOURCE_DIR}/src/StraightLineSurface.cxx
+     ${CMAKE_CURRENT_SOURCE_DIR}/src/PerigeeSurface.cxx
      PROPERTIES
      COMPILE_FLAGS "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}"
      COMPILE_DEFINITIONS "FLATTEN" )
diff --git a/Tracking/TrkDetDescr/TrkSurfaces/src/PerigeeSurface.cxx b/Tracking/TrkDetDescr/TrkSurfaces/src/PerigeeSurface.cxx
index 213749fe512c1eb2aac9da20f7a3afbf99385d4d..e720e6ef9fe260f664e9c49e1b0564173dd63b7c 100644
--- a/Tracking/TrkDetDescr/TrkSurfaces/src/PerigeeSurface.cxx
+++ b/Tracking/TrkDetDescr/TrkSurfaces/src/PerigeeSurface.cxx
@@ -48,6 +48,14 @@ Trk::PerigeeSurface::PerigeeSurface(std::unique_ptr<Amg::Transform3D> tTransform
   , m_lineDirection{}
 {}
 
+#if defined(FLATTEN) && defined(__GNUC__)
+// We compile this function 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
 Trk::PerigeeSurface::PerigeeSurface(const PerigeeSurface& pesf)
   : Surface(pesf)
   , m_lineDirection{}
@@ -110,6 +118,14 @@ Trk::PerigeeSurface::localToGlobal(const Trk::LocalParameters& locpars) const
     return new Amg::Vector3D(0., 0., locpars[Trk::z0] + (center().z()));
 }
 
+#if defined(FLATTEN) && defined(__GNUC__)
+// We compile this function 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
 // true local to global method/
 void
 Trk::PerigeeSurface::localToGlobal(const Amg::Vector2D& locpos,