From 498282206e512e179f212eb254c2956c1471af5d Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 19 Oct 2016 11:29:44 +0200 Subject: [PATCH] [registrar] Cache the System.Void type. Duration before: 1,60s Duration after: 1,54s Difference: -0,06s = -3,8% Memory usage hardly changed (-21 kb of 540 MB), but the number of method calls shrunk significantly. Method calls before: 86.720.379 Method calls after: 74.390.061 Difference: -12.330.318 = -14,2% The call to `GetSystemVoidType` was #2 on the list of method calls (whens sorted by 'self'), called 1072 times taking 1429 ms each time. After this change it's only called once (and obviously pushed way down the list). --- tools/common/StaticRegistrar.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/common/StaticRegistrar.cs b/tools/common/StaticRegistrar.cs index 57f3aec8b1ee..6008101b3c00 100644 --- a/tools/common/StaticRegistrar.cs +++ b/tools/common/StaticRegistrar.cs @@ -827,8 +827,12 @@ protected override TypeReference GetReturnType (MethodDefinition method) return method.ReturnType; } + TypeReference system_void; protected override TypeReference GetSystemVoidType () { + if (system_void != null) + return system_void; + // find corlib AssemblyDefinition corlib = null; AssemblyDefinition first = null; @@ -847,7 +851,7 @@ protected override TypeReference GetSystemVoidType () } foreach (var type in corlib.MainModule.Types) { if (type.Namespace == "System" && type.Name == "Void") - return type; + return system_void = type; } throw new Exception ("Couldn't find System.Void");