sqldelight icon indicating copy to clipboard operation
sqldelight copied to clipboard

Super slow speed on large data set of floating numbers for SELECT operation

Open konnovdev opened this issue 2 years ago • 5 comments

SQLDelight Version

1.5.3

Application Operating System

Android

Describe the Bug

Problem

Perfoming the following operation: Given a dataset of 1000 elements that contain floating numbers, perform SELECT * operation Takes a huge amount time (>1500 milliseconds), but it shouldn't

Code snippet

WeatherLog.sq

CREATE TABLE weatherLog(
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    temperature REAL,
    humidity REAL,
    pressure REAL
);

selectAll:
SELECT *
FROM weatherLog;

WeatherDbDataSource

    override suspend fun loadAll() {
        weatherLogQueries.selectAll()
    }

Performance result

SQLDelight performance screenshotperformance screenshot

Why is this a bug

The same operation takes no time on Room. Since both are wrappers over SQLite I expect the results of SQLDelight to be similar to Room. They are similar for strings. But not for real numbers, hence I assume there is a bug

Room performance screenshotperformance screenshot

Stacktrace

There are no errors in stacktrace

konnovdev avatar Jun 17 '22 14:06 konnovdev

    override suspend fun loadAll() {
        weatherLogQueries.selectAll()
    }

this isn't running any SQL, it's just creating the query type

AlecKazakova avatar Jun 17 '22 14:06 AlecKazakova

so I'm not sure what you're benchmarking

AlecKazakova avatar Jun 17 '22 14:06 AlecKazakova

@AlecStrong huh seems like i've missed the execute method for every operation that returns a Query<> object indeed. For some reason i assumed it executes the query automatically when i invoke selectAll(). I'll try that again

konnovdev avatar Jun 17 '22 15:06 konnovdev

@AlecStrong i've replaced it with weatherLogQueries.selectAll().execute() And the result is still 7000 milliseconds. The strange thing is this happens only for SELECT * and only for floating numbers, everything else works just fine

Performance screenshotperformance screenshot

konnovdev avatar Jun 17 '22 16:06 konnovdev

:+1: indeed very weird. I can take a look

AlecKazakova avatar Jun 17 '22 16:06 AlecKazakova