question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Native] More time is spent in stripping string margins than actually executing the DML queries

See original GitHub issue

Runtime 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()

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:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
JakeWhartoncommented, Jan 21, 2021

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.

0reactions
AlecStrongcommented, Feb 21, 2021

gonna close this out since it’ll happen with a kotlin upgrade eventually

Read more comments on GitHub >

github_iconTop Results From Across the Web

تويتر \ Jake Wharton على تويتر: "@winterbe_ @sur3shg That's ...
[Native] More time is spent in stripping string margins than actually executing the DML queries ·... Runtime Environment SQLDelight version: 1.4.4 ...
Read more >
Problem with BULK COLLECT with million rows - Ask TOM
Our code looks very simple. 1. We declared PL/SQL BINARY_INDEXed Tables to store the data in memory. 2. We used BULK COLLECT into...
Read more >
Legacy SQL Functions and Operators | BigQuery - Google Cloud
Queries that union a large number of tables typically run more slowly than queries that process the same amount of data from a...
Read more >
DBArtisan User Guide
Regardless of mode, all of the generated DML statements are viewable in the ... DBArtisan lets you remove database groups that you no...
Read more >
IBM Informix Messages and Corrections
Look for additional messages that explain the error. 4155 4GL run-time error number -number. For this 4GL runtime error, check the message for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found