none
Liqn Performance issue RRS feed

  • Question

  • OK guys no laughing

    I find this function is slow.

    I would like advice on a better way to do this

     

    Protected Function getCountLag() As Integer

            ' Get the start and min GC and max GC.

            Dim start = From sc In tempGameData.GroupBy(Function(g) g.GC).Where(Function(g) g.Count < N) Select sc.ElementAt(0).GC

            maxCount = start.Max : startCount = start.Min

            'I need to find the record in a collection that has this maxCount

            Dim mCount = From o In tempGameData Where o.GC = maxCount

            ' then get all the records with a draw less or =

            Dim recordCount = (From r In tempGameData Where r.Draw <= mCount(0).Draw).Count

            'determine the average the max count number plays

            Dim counters = From c In tempGameData Where c.BN = mCount(0).BN

            Dim futureCounter = CType((recordCount / counters.Count), Integer)

            FutureCount = (recordCount + futureCounter)

            Return FutureCount

        End Function


    Friday, May 10, 2013 9:53 AM

Answers

  • Basically 1200 records must not cause any problems cause this is nothing.

    Here is what I can suggest:

    1. Force to enumerate your query (do ToArray or ToList in the end of your query), cause if you are dealing with database, every time you are executing your statement it goes to database, that affects your performance.
    2. Do OrderBy, this will allow you to avoid calling Min and Max, your Min will be the first element of the collection and Max will be the last one
    3. Dealing with collection  will let you have a Count property of this collection, instead of calling method Count.

    Please Mark as Answer and Vote as Helpful if I helped.

    Also please visit my blog http://msguy.me/


    Saturday, May 11, 2013 7:57 PM

All replies

  • Please find out which exact part takes the long time to execute. I can see four queries,

    1. Dim start ...
    2. Dim mCount ...
    3. Dim recordCount ...
    4. Dim counters ...

    Try to analyze each of them step by step in debug mode, to find out where is the problem.


    Please Mark as Answer and Vote as Helpful if I helped.

    Also please visit my blog http://msguy.me/


    Saturday, May 11, 2013 12:25 PM
  • Hi

    recordCount seems to be the problem

    I seem to like linq maybe too much and find I am writing linq statements everywhere and wonder if I have gone too far with the above statements and had another look at what I am doing.

    Is what I have written normal or have I gone linq mad?

    For some reason I have found that statements I have written many times now seem to give me problems. The worst problem is using a linq statement to bring back a collection and then use max

    Dim maxID = (from x in y where ...).max which in some cases has stop working and find myself changing the statement with

    dim MaxID = (from x in y where ... take 1 without understanding why the code stop working, the collection has around 1200 type objects

    I have revisited my code and found ways to code without linq for the same result

    For instance Dim Start: I have restricted the data added to the tempGameData collection and now can index the data with tempGameData(0) as min and tempGameData(tempGameData.count) as max

     

    Do you know why the max statement may have issues for me and is the linq statement I have written gone too far?

    Thanks Michael


    Saturday, May 11, 2013 7:30 PM
  • Basically 1200 records must not cause any problems cause this is nothing.

    Here is what I can suggest:

    1. Force to enumerate your query (do ToArray or ToList in the end of your query), cause if you are dealing with database, every time you are executing your statement it goes to database, that affects your performance.
    2. Do OrderBy, this will allow you to avoid calling Min and Max, your Min will be the first element of the collection and Max will be the last one
    3. Dealing with collection  will let you have a Count property of this collection, instead of calling method Count.

    Please Mark as Answer and Vote as Helpful if I helped.

    Also please visit my blog http://msguy.me/


    Saturday, May 11, 2013 7:57 PM