[Native] More time is spent in stripping string margins than actually executing the DML queries
See original GitHub issueRuntime Environment SQLDelight version: 1.4.4 Application OS: iOS 14.0
Describe the bug
A simple UPSERT query:
upsert:
INSERT INTO Entity VALUES ?
ON CONFLICT (id, parentId) DO
UPDATE SET name = excluded.name, imageFilename = excluded.imageFilename, color = excluded.color;
Profiling with Xcode Instruments shows that, even with all compiler optimizations enabled (-opt
), the generated code spends more time in stripping margins than executing the query.
An example run:
- 600.60 ms
kfun:mypackage.EntityQueriesImpl.upsert
- 304.80 ms
kfun:kotlin.text#trimMargin$default@kotlin.String(kotlin.String?;kotlin.Int){}kotlin.String
- 279.00 ms (inlined)
NativeSqlDriver#execute()
- 278.10 ms
ConnectionWrapper#execute()
- …
- 76.00 ms
NativeStatement#execute()
- 76.00 ms
- …
- 278.10 ms
- 304.80 ms
It’s gonna take a very large dataset with lots of indexes to beat the time spent in trimming margins alone, notwithstanding the low hanging fruit in the native driver yet to be picked.
~While it could be K/N implementation of trimMargins()
being underwhelming,~[1] Do we really have to trim the margins from the generated SQL text at runtime? The SQLite compiler should deal with these varying amount of whitespaces alright, shouldn’t it?
[1] Turns out it is common code.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top GitHub Comments
I’m pretty sure I landed the optimization for IR which should include native. But this was like… two years ago, so my memory is fuzzy.
I’m opposed to any action on our side. Let’s fix the Kotlin compiler.
gonna close this out since it’ll happen with a kotlin upgrade eventually