Abysmal performance in Interop on iOS · Issue #19079 · dotnet/macios (original) (raw)

From @damiand2 on Wed, 20 Sep 2023 14:59:32 GMT

Description

During tests on iOS for self made binding library that binds to xcframework for google map utils (https://github.com/googlemaps/google-maps-ios-utils) i found that application slows down to a crawl in specific scenario. After instrumenting app (Instruments on macos) i found that that perf drop was related to switch between my code and native one (overriding method on class that binds to native one). After removal of that override, app is fast again.
This kind of interop was also used on Xamarin.Forms (albeit with different binding library and earlier native library version) and there were no problems. Sample screen from Instruments showing dramatic cpu time in specific runtime methods responsible for interop between .net and native code:
image

Steps to Reproduce

  1. clone https://github.com/damiand2/MauiBugiOSInteropPerformance
  2. put your own google map key inside MauiProgram.cs (library deals with google maps, it was the easiest for me to provide quick sample), set up nuget local source to bindings folder inside repo
  3. uncomment method public override bool ShouldRenderAsCluster(ICluster cluster, float zoom) inside ClusterRendererHandler.cs
  4. run app on simulator or real iphone, does not matter
  5. Map will take you to Czech country, library uses clustering of pins, double click anywhere to zoom in and therefore break down clusters into smaller ones, repeat this untill there are no more cluster and you only get singluar pins.
  6. try to move map left and right, notice how sluggish it becomes (UI hangs for almost second sometimes)
  7. Stop app, comment back that override from 3rd point, restart app
  8. repeat steps from 5th point, notice that now map scrolling is very smooth

https://github.com/damiand2/MauiBugiOSInteropPerformance

Version with bug

7.0.92

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

Copied from original issue dotnet/maui#17516