Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS App crash (or does not work as expected) in Release mode when using default settings and sqlite #20342

Closed
borrmann opened this issue Feb 3, 2024 · 6 comments
Labels
platform/iOS 🍎 t/bug Something isn't working

Comments

@borrmann
Copy link
Contributor

borrmann commented Feb 3, 2024

Description

Following issue from 2021.

Using AOT compilation does give a warning that you should test your app in release mode, but the issue has been present since 2021 and the library is recommended in the official docs of MAUI.
Since many apps use and depend on this library, the docs should maybe give a warning about this explicitly or recommend to use version 1.7.335?
There has been a PR that claims to fix those issues.
Maybe, this could be resolved if someone from the MAUI team reaches out to the library owner?

Steps to Reproduce

  1. Use SQLite pcl-net library and compile with AOT

Link to public reproduction project repository

Version with bug

8.0.6

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

No response

Did you find any workaround?

use version 1.7.335

Relevant log output

Attempting to JIT compile method '(wrapper delegate-invoke) void
@borrmann borrmann added the t/bug Something isn't working label Feb 3, 2024
@drasticactions
Copy link
Contributor

drasticactions commented Feb 3, 2024

I think there are a few things here:

  • Checking the docs, you are right that that library is listed there. Seeing that the last time it was updated was two years ago, I have a feeling it's not maintained anymore, or any possible fixes to it would be limited. It is called out as a third party library, but IMO it may make more sense to updated it to use a different library with more support, like Dapper or EFCore. CC @davidbritch
  • As for your issue, it's an AOT/runtime issue and it can't be addressed in this repo. Going by your issue thread, it goes to xamarin-macios and then gets moved to mono where it's mentioned that it was "fixed" but I'm not sure where, and the issue is still open. @dalexsoto would you remember anything about this?

To workaround this, you should be able to turn on the Mono Interpreter (Open your csproj and set <UseInterpreter >true</UseInterpreter>) and that may get it working in Release mode. But IMO, personally (I do not work on the MAUI Team, I'm just within .NET), I would migrate to something else and not rely on that library.

Also, beyond the docs, the root issue in that library is not something that can be addressed in this repo. It's a AOT issue in the runtime, and would either need to be worked around in that library, or within the runtime. Maybe both. But not something that can be fixed in this repo, which is for the MAUI UI framework.

@borrmann
Copy link
Contributor Author

borrmann commented Feb 4, 2024

Using the interpreter has major performance impacts that are worse than using version 1.7.335, so in my case that is the better workaround.

I agree, I would really like to migrate to a different local storage library.
I will definitely have a look into Dapper and EF Core, thanks!
I really wonder why EF Core is not recommended in the first place, though?
Since the docs mention sql-pcl, I was sure there would be a reason for that. If EF Core works well, why isn't it the one that is linked in the docs and the tutorial as it is developed my MS?
So, I would like to switch, once it is documented, supported and recommended by MAUI/ Microsoft or Xamarin as local storage is a core feature and of course I don't want to rely on anything unstable for something that is so essential, which is why I chose the recommended library.

And in the meantime, if sqlite-pcl-net is still the way to go, then the docs should mention that there are major limitations (or shouldnt recommend to use the latest version) and then I agree, this is all that can be done here.

@drasticactions
Copy link
Contributor

IMO while enabling the interpreter could potentially have impacts in your applications performance, I would be very surprised if it was that drastic turning it on for Release mode, considering that it is on by default for Debug applications. Of course, that should never be an intended solution to fixing this issue, it would be to fix it in the library and/or runtime.

I believe the origins of the docs were based on Xamarin.Forms versions. It would have made more sense at the time to reference that specific library then, as it was very popular and used commonly within Xamarin apps. For MAUI, it was most likely ported from that version, as the library itself still works and the author of it hasn't "deprecated" it formally, as far as I can tell. So whoever wrote that doc probably had that in mind. Reading the doc, IMO, I don't think it was intended to be read as the "preferred" library or the "correct" library to use, but "one of" the ways to do it.

As for EFCore (which is an MS developed library) that does have docs for Xamarin.Forms, which should probably get ported to MAUI at some point.

Another important point with many of these ORM SQLite libraries and iOS/Mac, including EFCore and Dapper, is that you're going to have issues with them and NativeAOT (Which is, more or less, the same issue you're having right now with sqlite-net-pcl). SQLite libraries tend to use lots of reflection and that breaks AOT. EFCore is working on supporting it, and there is a Dapper.AOT library to help make sure you write code that works with AOT. The general solution for working around these libraries while they implement support for it is to... enable the Mono Interpreter. Again, this isn't a thing specific to MAUI UI, it's a library/runtime situation.

@borrmann
Copy link
Contributor Author

borrmann commented Feb 4, 2024

Just FYI, I have done performance tests for the Interpreter in Release mode using iOS' hang detection with my app.
The biggest issue I had is with navigation. While with Interpreter I get '>500ms hangs' for many many navigations, I barely get any '>250ms hangs' without.
The worst thing I found was tapping on a native notification outside the app, that triggers some code to open a page which took >2s with Interpreter in some cases, while the Page opened instantly when I had it turned off.

I did see the docs for Xamarin.Forms and EF Core, but then that is as old as the latest updates for the pcl library, so I didnt think this would be safe to use either and I guess that is the case looking at your linked issue and following your explanations.

Especially, if this is always the case when using sqlite, then it would be great if it could be updated in the docs for whichever library is recommended.

@jsuarezruiz
Copy link
Contributor

@rolfbjarne Thoughts?

@ivanpovazan
Copy link
Member

This is a dotnet/runtime issue.
I opened dotnet/runtime#98428 for tracking.

@github-actions github-actions bot locked and limited conversation to collaborators Mar 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform/iOS 🍎 t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants