Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[foundation] Cache parts of
NSObject.ConformsToProtocol
Note that the call to native code still _always_ happen (not cached) since the application could use `class_addProtocol` to add conformance to a protocol at runtime. So the cache is limited to the .net specific reflection code that is present (only) when the dynamic registrar is included inside applications. This is the default for macOS apps, but not iOS / tvOS or MacCatalyst apps. The linker/trimmer will remove the caching code when the dynamic registrar is removed. IOW this PR should not have any impact, performance or size, for most iOS apps (where the dynamic registrar is removed by default). Fix xamarin#14065 Running Dope on macOS, a 2 minutes benchmark, shows the following times (in seconds and percentage) spent calling this API: **Before** * `RemoveFromSuperview` 7.99s (6.4%) * `NSObject.ConformsToProtocol` 3.26s (2.6%) **After** * `RemoveFromSuperview` 4.67s (3.8%) * `NSObject.ConformsToProtocol` 0.32s (.26%) So a 10x improvements on `ConformsToProtocol` which helps a lot the code path calling `RemoveFromSuperview`.
- Loading branch information