I have deployed a application in release mode (x64) which I expected to be fast, and I noticed that there is a severe slowdown whenever a new method, or set of methods is ex
Wow. Such delays are unusual for the JIT. Profile your app to make sure the bottleneck is the JIT.
Now, if it's really the JIT, here's a much better method than adding a dummy argument everywhere:
Use RuntimeHelpers.PrepareMethod on each non-generic method. This function will force the JIT to process it.
You can also use RunClassConstructor method on each class to... well, run their static constructors.
Here's some (totally untested) code:
foreach (var type in Assembly.GetExecutingAssembly().GetTypes())
{
if (type.IsGenericTypeDefinition || type.IsInterface)
continue;
RuntimeHelpers.RunClassConstructor(type.TypeHandle);
foreach (var method in type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly))
RuntimeHelpers.PrepareMethod(method.MethodHandle);
}