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.

Performance issue

See original GitHub issue

We have encountered a very similar issue however even the latest (3.4.5) version doesn’t seem to fix this. It has improved but it’s not on the same level as before. Our situation is the following, we upgraded from 2.9.0 to 3.1.6 and noticed that the memory usage of our application was quite a bit higher then before.

So i setup a small console project that executes an update command on an in memory SQLite database (link to repo), and added some benchmarking library. Not only is the memory usages in 2.9.0 much better, the performance is also quite a lot better. These are the result when run on my machine:

3.4.5

Method Mean Error StdDev Gen 0 Gen 1 Allocated
Small_UpdateStatement_With_Variable_Parameters 7,148.1 us 105.17 us 121.11 us 93.7500 62.5000 414 KB
Small_UpdateStatement_With_Static_Parameters 183.0 us 2.94 us 3.27 us 5.3711 - 22 KB
Large_UpdateStatement_With_Variable_Paramters 25,341.0 us 483.85 us 557.20 us 125.0000 - 922 KB
Large_UpdateStatement_With_Static_Paramters 293.6 us 4.63 us 4.96 us 8.7891 - 36 KB
Large_UpdateStatement_With_Variable_Paramters_With_ClearCaches 19,227.3 us 1,071.55 us 1,234.00 us 62.5000 31.2500 298 KB

3.1.6

Method Mean Error StdDev Gen 0 Gen 1 Allocated
Small_UpdateStatement_With_Variable_Parameters 11,831.9 us 176.45 us 188.80 us 140.6250 62.5000 675 KB
Small_UpdateStatement_With_Static_Parameters 245.3 us 31.17 us 35.90 us 6.1035 - 25 KB
Large_UpdateStatement_With_Variable_Paramters 38,473.9 us 2,112.70 us 2,260.57 us 312.5000 - 1,593 KB
Large_UpdateStatement_With_Static_Paramters 326.5 us 5.19 us 5.33 us 9.2773 - 39 KB
Large_UpdateStatement_With_Variable_Paramters_With_ClearCaches 16,906.5 us 263.30 us 303.22 us 93.7500 31.2500 403 KB

2.9.0

Method Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated
Small_UpdateStatement_With_Variable_Parameters 2,386.7 us 34.38 us 39.59 us 50.7813 15.6250 3.9063 248 KB
Small_UpdateStatement_With_Static_Parameters 169.0 us 6.39 us 6.83 us 4.8828 - - 21 KB
Large_UpdateStatement_With_Variable_Paramters 5,290.6 us 43.50 us 46.55 us 125.0000 7.8125 - 567 KB
Large_UpdateStatement_With_Static_Paramters 264.9 us 8.48 us 9.43 us 7.8125 - - 33 KB
Large_UpdateStatement_With_Variable_Paramters_With_ClearCaches 1,999.7 us 24.64 us 26.36 us 35.1563 11.7188 - 151 KB

The thing is that when the update statement contains the same values in the set (in other words set(columnname, value)), there seems to be no problem. It is only when the value changes that the issue arises.

When analysing the problem with dotMemory, you can see that there are a lot of QueryCacheEntry<TESTTABLE> objects in memory, while in 2.9.0 this is not the case (I don’t think QueryCache<T> was a thing in 2.9.0). This memory snapshot is after executing Large_UpdateStatement_With_Variable_Paramters 200 times.

3.1.6 3 1 6_querycache

Also the sql text of the update is saved in memory a hundred times: 3 1 6_stringduplicate

This seems a bit weird to me.

2.9.0 2 9 0_querycache 2 9 0_stringduplicate

The weird part to me is how 2.9.0 seems to use less memory and is more performant. It would be ok if 3.1.6 had higher memory usage but the queries were faster. But this isn’t the case. Also adding Query.ClearCaches after the update statement seems to improve the performance and the memory usage, this to me indicates that something is wrong.

_Originally posted by @aarondk-dev in https://github.com/linq2db/linq2db/issues/2556#issuecomment-940080728_

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:14 (10 by maintainers)

github_iconTop GitHub Comments

3reactions
MaceWinducommented, Oct 12, 2021

Good news. Looks like in next release we will have huge improvement here. I’ve managed to fix mentioned issue with Set and already got huge perf/memory bust. Still need to check other APIs for similar issues and check if there is more space for fixes.

1reaction
aarondk-devcommented, Oct 13, 2021

I’m sorry I made a mistake, it is indeed fixed, my apologies.

PR:

Method Mean Error StdDev Gen 0 Gen 1 Allocated
Small_UpdateStatement_With_Variable_Parameters 259.73 us 8.778 us 10.108 us 6.8359 - 29 KB
Small_UpdateStatement_With_Static_Parameters 261.01 us 6.815 us 7.575 us 6.8359 - 29 KB
Large_UpdateStatement_With_Variable_Paramters 404.24 us 6.504 us 6.679 us 12.2070 - 52 KB
Large_UpdateStatement_With_Static_Paramters 404.40 us 5.259 us 5.627 us 12.2070 - 52 KB
Large_UpdateStatement_With_Variable_Paramters_With_ClearCaches 19,069.81 us 211.121 us 234.660 us 62.5000 31.2500 307 KB
Large_Compiled_UpdateStatement_With_Variable_Paramters 91.16 us 1.223 us 1.360 us 3.7842 - 16 KB
Large__UpdateStatement_With_Variable_Paramters_Using_Expression_Overload 471.10 us 37.669 us 43.379 us 12.6953 - 54 KB
Read more comments on GitHub >

github_iconTop Results From Across the Web

Dealing with Performance Problems
Types of Performance Problems ; Quantity of work (untimely completion, limited production). Poor prioritizing, timing, scheduling; Lost time ; Quality of work ( ......
Read more >
Handling Performance Issues With Grace
Low Productivity or Late Completion – Make sure you've been clear about the requirements and expectations of the job. · Poor Quality of...
Read more >
What is a performance problem?
Generally, a performance problem is the result of some workload not getting the resources it needs to complete in time. Or the resource...
Read more >
5 Common Reasons for Performance Issues (Plus 3 Tips to ...
1. They lack knowledge or skill. · 2. They have unclear or unrealistic expectations. · 3. They aren't motivated. · 4. The job...
Read more >
Performance Issue Root-Cause Diagnostic
Tool Overview: Accurately assessing employee performance issues is a critical part of providing high-quality performance evaluations.
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