Do not create R2R in memory hashes if profiler is not present or hasn't added types...
authorDavid Mason <davmason@microsoft.com>
Fri, 5 Mar 2021 23:04:56 +0000 (15:04 -0800)
committerGitHub <noreply@github.com>
Fri, 5 Mar 2021 23:04:56 +0000 (23:04 +0000)
* only create lazy map if profiler added types

* also don't create for ApplyMetadata if they haven't added new types

* add check to skip call if no profiler was called

* Update src/coreclr/vm/ceeload.cpp

Co-authored-by: Brian Robbins <brianrob@microsoft.com>
Co-authored-by: Brian Robbins <brianrob@microsoft.com>
src/coreclr/vm/ceeload.cpp

index e121270..4a71037 100644 (file)
@@ -220,6 +220,14 @@ void Module::UpdateNewlyAddedTypes()
     DWORD countExportedTypesAfterProfilerUpdate = GetMDImport()->GetCountWithTokenKind(mdtExportedType);
     DWORD countCustomAttributeCount = GetMDImport()->GetCountWithTokenKind(mdtCustomAttribute);
 
+    if (m_dwTypeCount == countTypesAfterProfilerUpdate
+        && m_dwExportedTypeCount == countExportedTypesAfterProfilerUpdate
+        && m_dwCustomAttributeCount == countCustomAttributeCount)
+    {
+        // The profiler added no new types, do not create the in memory hashes
+        return;
+    }
+
     // R2R pre-computes an export table and tries to avoid populating a class hash at runtime. However the profiler can
     // still add new types on the fly by calling here. If that occurs we fallback to the slower path of creating the
     // in memory hashtable as usual.
@@ -280,6 +288,7 @@ void Module::NotifyProfilerLoadFinished(HRESULT hr)
             m_dwCustomAttributeCount = GetMDImport()->GetCountWithTokenKind(mdtCustomAttribute);
         }
 
+        BOOL profilerCallbackHappened = FALSE;
         // Notify the profiler, this may cause metadata to be updated
         {
             BEGIN_PIN_PROFILER(CORProfilerTrackModuleLoads());
@@ -292,13 +301,15 @@ void Module::NotifyProfilerLoadFinished(HRESULT hr)
                     g_profControlBlock.pProfInterface->ModuleAttachedToAssembly((ModuleID) this,
                                                                                 (AssemblyID)m_pAssembly);
                 }
+
+                profilerCallbackHappened = TRUE;
             }
             END_PIN_PROFILER();
         }
 
         // If there are more types than before, add these new types to the
         // assembly
-        if (!IsResource())
+        if (profilerCallbackHappened && !IsResource())
         {
             UpdateNewlyAddedTypes();
         }
@@ -13832,4 +13843,3 @@ void EEConfig::DebugCheckAndForceIBCFailure(BitForMask bitForMask)
     }
 }
 #endif // defined(_DEBUG) && !defined(DACCESS_COMPILE)
-