praeclarum / sqlite-net

Simple, powerful, cross-platform SQLite client and ORM for .NET
MIT License
4.03k stars 1.42k forks source link

sqlite-net-pcl super slow in loading database on android... it takes 20 seconds to display data. #1118

Open nextcodelab opened 2 years ago

nextcodelab commented 2 years ago

https://www.nuget.org/packages/sqlite-net-pcl I tried it on android phones, Android TV, Android tablet. my database file is already store on filesystem from embedded resource stream... 20+ seconds to display data. sometimes it fast but always take long to read.. here the all database file samples. https://github.com/fangniude/bible-data/blob/master/bibledata-en-asv.zip?raw=true

.NetStantard 2.0 to Net Maui project.

public IEnumerable<books> GetBooks()
        {
            using (var session = new SQLiteConnection(SqlFilePath))
            {
                List<books> books = null;
                try
                {
                    books = session.Table<books>().ToList();
                }
                catch
                {
                    if (File.Exists(SqlFilePath))
                    {
                        File.Delete(SqlFilePath);
                    }

                }
                return books;
            }
        }
public IEnumerable<chapters> GetChapters(books books)
        {
            using (var session = new SQLiteConnection(SqlFilePath))
            {
                var items = session.Table<chapters>().Where(p=>p.reference_human == books.human).ToList();
                return items;
            }
        }

Screenshot 2022-05-26 203450

I will upload loading time...

https://user-images.githubusercontent.com/73583588/170488415-abbf443b-a460-4f53-acc7-855e3a49e6bf.mp4

//new update

<PackageReference Include="sqlite-net-pcl" Version="1.8.116" />
        <PackageReference Include="SQLitePCLRaw.core" Version="2.1.0" />
        <PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.1.0" />
        <PackageReference Include="SQLitePCLRaw.provider.dynamic_cdecl" Version="2.1.0" />
        <PackageReference Include="SQLitePCLRaw.provider.sqlite3" Version="2.1.0" />
acxsasx commented 2 years ago

I have found slowness as well. I have not looked at too hard yet. I manually coded the SQL and it performed.

*Edit: Decided to look into my slowness and found I defaulted the recursive parameter GetAllWithChildren to 'true'. Sigh.

ericsink commented 2 years ago

Not sure what is causing OP's slowness problem, but their package config is weird.

Having Microsoft.Data.Sqlite and sqlite-net-pcl might be causing problems, because both are built on SQLitePCLRaw, and might be bringing in different configurations.

Ignoring that...

If you have sqlite-net-pcl, it is bringing in SQLitePCLRaw.bundle_green. You can explicitly reference that package to bring in a newer version, which you are doing.

However, if you do that, you don't need to explicitly reference SQLitePCLRaw.core or the two providers. The bundle_green package references these for you.