-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Closed
Copy link
Labels
Description
There's a TODO in the code:
runtime/src/coreclr/tools/Common/TypeSystem/Common/TypeHashingAlgorithms.cs
Lines 229 to 234 in b438888
public static int ComputeMethodHashCode(int typeHashCode, int nameOrNameAndGenericArgumentsHashCode) | |
{ | |
// TODO! This hash combining function isn't good, but it matches logic used in the past | |
// consider changing to a better combining function once all uses use this function | |
return typeHashCode ^ nameOrNameAndGenericArgumentsHashCode; | |
} |
Notably, this comes up as a sore spot in my profiles:
Changing to HashCode.Combine
yields about >20% less hash collisions in this method alone:

This compilation speed improvement is quite noticable.
Unfortunately, there seems to be some dependency on the hash combining algorithm somewhere in the code because this produces an executable that fails to run at runtime:
Process terminated. Failed to create generic virtual method implementation
Declaring type: Microsoft.Extensions.Options.OptionsBuilder`1<Microsoft.Extensions.Options.StartupValidatorOptions>
Method name: Configure
Instantiation:
Argument 00000000: Microsoft.Extensions.Options.IOptionsMonitor`1<Microsoft.Extensions.DependencyInjection.MetricsServiceExtensions+NoOpOptions>
at System.RuntimeExceptionHelpers.FailFast(String, Exception, String, RhFailFastReason, IntPtr, IntPtr) + 0x2b0
at Internal.Runtime.TypeLoader.TypeLoaderEnvironment.ResolveGenericVirtualMethodTarget(RuntimeTypeHandle, RuntimeMethodHandle) + 0x210
at System.Runtime.TypeLoaderExports.<>c.<GVMLookupForSlotSlow>b__8_0(IntPtr context, IntPtr signature, Object contextObject, IntPtr& auxResult) + 0x31
at System.Runtime.TypeLoaderExports.CacheMiss(IntPtr, IntPtr, RuntimeObjectFactory, Object) + 0x28
at System.Runtime.TypeLoaderExports.GVMLookupForSlotSlow(Object, RuntimeMethodHandle) + 0x4e
at System.Runtime.TypeLoaderExports.GVMLookupForSlot(Object, RuntimeMethodHandle) + 0x9a
at Microsoft.Extensions.DependencyInjection.OptionsBuilderExtensions.ValidateOnStart[TOptions](OptionsBuilder`1) + 0x6e
at Microsoft.Extensions.DependencyInjection.MetricsServiceExtensions.AddMetrics(IServiceCollection) + 0x47
at Microsoft.Extensions.DependencyInjection.HttpClientFactoryServiceCollectionExtensions.AddHttpClient(IServiceCollection) + 0x26
at MailClient.Program.SetUpDependencyInjection() + 0x2a9
at MailClient.Program.Main(String[] args) + 0xd2
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
No status