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.

ChildrenQueryable 10 x slower than new Query

See original GitHub issue

Hey,

when i’m doing

var isbnGroups = _isbnService.GetAllISBNGroups().ToList();

var list = new List<ISBNGroupModel>();
foreach (var group in isbnGroups)
{
    list.Add(new ISBNGroupModel()
    {
        BaseNumber = group.BaseNumber,
        Count = group.Count,
        AvailableCount = group.Numbers.ChildrenQueryable().Count()
    });
}
return Ok(list);

it takes about 700-900 ms, with 1 ISBN Group and 9999 ISBNs (Numbers)

when doing

var isbnGroups = _isbnService.GetAllISBNGroups().ToList();

var list = new List<ISBNGroupModel>();
foreach (var group in isbnGroups)
{
    var childrenCount = DB.Queryable<ISBN>().Count(x => x.ISBNGroup.ID == group.ID);
    list.Add(new ISBNGroupModel()
    {
        BaseNumber = group.BaseNumber,
        Count = group.Count,
        AvailableCount = childrenCount
    });
}
return Ok(list);

it takes about 48-172 ms…

Btw, is there a better way to count a Many Child Collection?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dj-nitehawkcommented, Oct 17, 2019

released v8.10 with Many<T>.ChildrenCount() which does the above internally.

    count = group.Numbers.ChildrenCount()

will you let me know how fast this method works on your 10k isbn records? thanks!

0reactions
Seydencommented, Oct 17, 2019

Oh btw, its around 35 ms, where my fastest hack implementation was 48 ms

Read more comments on GitHub >

github_iconTop Results From Across the Web

Entity Framework query slow, but same SQL in SqlQuery is ...
The reason of slowing down my EF queries was comparing not nullable scalars with nullable scalars: long? userId = 10; // nullable scalar...
Read more >
sql server - Why would a query in code be slower than a ...
We are currently facing an issue where the same query executed in the code takes (on average) 15-20 seconds. The same query on...
Read more >
Same queries run slower on new system?
I have identical copies of MAINDB on OLDBOX and NEWBOX, and NEWBOX beats OLDBOX's performance by a solid 10-20% for running reports. Oddly, ......
Read more >
Very Slow SQL query - Fast in SSMS
I have an additional CF10 server that seems to run the query perfectly fine on a test page. The query is pretty much...
Read more >
Troubleshoot slow-running queries - SQL Server
This article describes how to handle a performance issue that applications may experience when using SQL Server.
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