Open mfbx9da4 opened 1 year ago
Update, I've discovered that the line which is taking almost one second actually has nothing to do with serializing JS objects, it is in fact
if (getNextRowOrTrue(statement.stmt)) {
On the last iteration it takes 1 second to execute this line 🤯
Update it's dependent on the query, see the culprit line in this query below:
WITH tmp AS (
SELECT
e.id,
datetime(date(start_at / 1000, 'unixepoch', 'utc'), 'utc') AS start_of_day_timestamp
FROM events e
LIMIT 100
)
SELECT
e.id,
start_of_day_timestamp,
-- Adding the below line causes the query to hang before returning SQLITE_DONE
ROW_NUMBER() OVER ( PARTITION BY start_of_day_timestamp ) AS row_num
FROM tmp e;
Toggling the above line will cause sqlite3_step(stmt)
to hang for 1 second before returning SQLITE_DONE
, running the same query is instant when using a cli / other interface with sqlite so this could still be a watermelon bug
There's nothing obviously wrong, so it's going to be hard for me to help or debug without a working reproducible demo.
It's strange that you say that it works instantly elsewhere. I can't rule out a 🍉 bug, but what can also be the difference is:
You can verify that you're using the exact same sqlite version and same configuration to try to narrow down where the issue is.
As for hanging at the last step - I suspect that after getting all rows, some final processing or cleanup is done and that's why you see a hang there. But I'm not sure what exactly it's doing. You can use a native profiler (e.g. Instruments) to get insights into where sqlite is spending its time on.
Thanks for your response!
I suspect that after getting all rows, some final processing or cleanup is done
Yeah 💯
You can use a native profiler (e.g. Instruments) to get insights into where sqlite is spending its time on.
🍉 includes sqlite from iOS so when I hit pause I'm inside some arbitrary assembly. I'll have to compile from the amalgamated source.
sqlite configuration done at launch (e.g. WAL mode)
Good idea, I'll try toggling journal_mode and locking_mode.
sqlite version (bug in old sqlite version?)
Unlikely as I'm running on a recent iOS (16)
I'm using
unsafeQueryRaw
and it's weirdly slow. I don't see why it is though as it's not too different from a normalquery
. I've added the following timings:The output timings in microseconds:
Note this query is returning just
367
results and each result looks like this:There must be something really funky going on for it to take 1 second to serialize 367 JS objects 🤔 .
Note I'm using Hermes and this profiling was done on simulator in debug mode.
Any ideas what to try next @radex? I'll keep digging though.