Extend JNI to Managed type map caching - #9818
Conversation
| // cache shortcuts for the class names of the subclasses in the hierarchy we just explored | ||
| if (class_names is not null) { | ||
| foreach (var subclass_name in class_names) { | ||
| TypeManagerMapDictionaries.JniToManaged.Add (subclass_name, type); |
There was a problem hiding this comment.
Is the type here actually the correct one? It seems like it would be the final type it found and not the one that matches the class_name earlier in the loop.
Do you need to store a (string, Type) tuple, so you have the previous Type instance?
There was a problem hiding this comment.
You're right that it is not an exact match. On the other hand, by inspecting the superclasses in the type hierarchy we should always arraive at the same type. So my idea was to cache this "shortcut".
The only problem I can think of is if we stored this "shortcut", any later call to TypeManager.RegisterType with a more specific mapping would be ignored. This could break dynamic registration. I will need to give this some more thought.
This PR suggests caching "shortcuts" between class names which don't have a direct mapping to a managed class, but their base class has one. This should reduce the need to repeatedly call
GetJavaToManagedTypeand inspect Java type hierarchies.