Skip to content

Commit 7e4db23

Browse files
committed
Drop MaybeType from ClassManager for performance
1 parent a31f078 commit 7e4db23

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/runtime/classmanager.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ internal class ClassManager
3131
BindingFlags.Public |
3232
BindingFlags.NonPublic;
3333

34-
private static Dictionary<MaybeType, ClassBase> cache;
34+
// TODO: Issue #1407
35+
// Using Type instead of MaybeType because of performance reduction
36+
// by implicitly converting Types to MaybeTypes to access cache
37+
private static Dictionary<Type, ClassBase> cache;
3538
private static readonly Type dtype;
3639

3740
private ClassManager()
@@ -49,7 +52,7 @@ static ClassManager()
4952

5053
public static void Reset()
5154
{
52-
cache = new Dictionary<MaybeType, ClassBase>(128);
55+
cache = new Dictionary<Type, ClassBase>(128);
5356
}
5457

5558
internal static void DisposePythonWrappersForClrTypes()
@@ -100,7 +103,7 @@ internal static void SaveRuntimeData(RuntimeDataStorage storage)
100103
storage.AddValue("cache", cache);
101104
foreach (var cls in cache)
102105
{
103-
if (!cls.Key.Valid)
106+
if (cls.Key == null)
104107
{
105108
// Don't serialize an invalid class
106109
continue;
@@ -141,19 +144,19 @@ internal static void SaveRuntimeData(RuntimeDataStorage storage)
141144

142145
internal static Dictionary<ManagedType, InterDomainContext> RestoreRuntimeData(RuntimeDataStorage storage)
143146
{
144-
cache = storage.GetValue<Dictionary<MaybeType, ClassBase>>("cache");
145-
var invalidClasses = new List<KeyValuePair<MaybeType, ClassBase>>();
147+
cache = storage.GetValue<Dictionary<Type, ClassBase>>("cache");
148+
var invalidClasses = new List<KeyValuePair<Type, ClassBase>>();
146149
var contexts = storage.GetValue <Dictionary<IntPtr, InterDomainContext>>("contexts");
147150
var loadedObjs = new Dictionary<ManagedType, InterDomainContext>();
148151
foreach (var pair in cache)
149152
{
150-
if (!pair.Key.Valid)
153+
if (pair.Key == null)
151154
{
152155
invalidClasses.Add(pair);
153156
continue;
154157
}
155158
// re-init the class
156-
InitClassBase(pair.Key.Value, pair.Value);
159+
InitClassBase(pair.Key, pair.Value);
157160
// We modified the Type object, notify it we did.
158161
Runtime.PyType_Modified(pair.Value.tpHandle);
159162
var context = contexts[pair.Value.pyHandle];

0 commit comments

Comments
 (0)