[Evaluate] - optimize listview controls filling in TVSetup - Channel list for groups | Page 2

Discussion in 'Submit: code patches (MediaPortal/TV-Server/etc.)' started by Vasilich, July 1, 2011.

  1. mm1352000
    • Team MediaPortal

    mm1352000 Development Group

    Joined:
    September 1, 2008
    Messages:
    21,527
    Likes Received:
    4,738
    Ratings:
    +8,205 / 17
    Home Country:
    New Zealand New Zealand
    Hi again Vasilich



    Last thing before I go to bed. :)
    1. Yes the binaries were built on latest SVN.
    2. Patches attached.

    mm
     

    Attached Files:

    • Like Like x 1
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. Vasilich
    • Team MediaPortal

    Vasilich Test Group

    Joined:
    August 30, 2009
    Messages:
    3,390
    Likes Received:
    608
    Gender:
    Male
    Occupation:
    Developer
    Location:
    Germany, Mayence
    Ratings:
    +1,172 / 2
    Home Country:
    Russian Federation Russian Federation
    Show System Specs
    thanks mm, i have tested all versions of SetupTV and wrote down time it took for populating of All Channels TV group:
    1. original unpatched: 80 seconds
    2. with listview fill optimization: 37 seconds
    3. with listview fill optimization and removed second SQL query: 26 seconds
    4. with dictionary: 14 seconds.
    So i think it is clear where we should tend. I will try to further optimize dictionary patch (there are some points to try ;) ) and post the results later.
     
  4. mm1352000
    • Team MediaPortal

    mm1352000 Development Group

    Joined:
    September 1, 2008
    Messages:
    21,527
    Likes Received:
    4,738
    Ratings:
    +8,205 / 17
    Home Country:
    New Zealand New Zealand
    Excellent :)
    I'll leave that in your capable hands. Obviously whatever we do should be applied to the full channel lists as well as the groups, and both the TV and radio code will need updating. If you're quick then it *might* be possible to get this in 1.2.0rc (no promises).

    mm
     
  5. gibman
    • Premium Supporter

    gibman Retired Team Member

    Joined:
    October 4, 2006
    Messages:
    2,998
    Likes Received:
    1,321
    Occupation:
    Developer
    Location:
    Aarhus
    Ratings:
    +1,372 / 0
    Home Country:
    Denmark Denmark
    this is potentially an expensive call:

    Code (Text):
    1.  
    2.  try
    3. +          {
    4. +            tuningDetails = d[channel.IdChannel];
    5. +          }
    6. +          catch (KeyNotFoundException)
    7. +          {
    8. +            tuningDetails = new List<TuningDetail>();
    9. +          }
    10.  
    use .TryGetValue whenever possible for performance.

    Code (Text):
    1.  
    2. IList<TuningDetail> tuningDetails;
    3. if (!d.TryGetValue(channel.IdChannel, out tuningDetails) )
    4. {
    5.    tuningDetails = new List<TuningDetail>();
    6. }
    7.  
    /gibman
     
    • Like Like x 1
  6. mm1352000
    • Team MediaPortal

    mm1352000 Development Group

    Joined:
    September 1, 2008
    Messages:
    21,527
    Likes Received:
    4,738
    Ratings:
    +8,205 / 17
    Home Country:
    New Zealand New Zealand
    Thanks gibman :D
    My C# inexperience showing... I would have thought they used some kind of fast-to-evaluate hashing function for key -> value lookup.
     
  7. gibman
    • Premium Supporter

    gibman Retired Team Member

    Joined:
    October 4, 2006
    Messages:
    2,998
    Likes Received:
    1,321
    Occupation:
    Developer
    Location:
    Aarhus
    Ratings:
    +1,372 / 0
    Home Country:
    Denmark Denmark
    no problem..

    u can even do something like:

    Code (Text):
    1.  
    2.  
    3. IList<TuningDetail> tuningDetails;
    4. bool hasTuningDetails = d.TryGetValue(channel.IdChannel, out tuningDetails);
    5. if (hasTuningDetails)
    6. {
    7.    foreach (TuningDetail detail in tuningDetails)
    8.           {
    9.             if (detail.FreeToAir)
    10.             {
    11.               hasFta = true;
    12.             }
    13.             if (!detail.FreeToAir)
    14.             {
    15.               hasScrambled = true;
    16.             }
    17.           }
    18. }
    19.  
    20. ...
    21.  
    22. if (hasTuningDetails && tuningDetails.Count > 0)
    23. {
    24.   item.SubItems.Add(tuningDetails[0].ChannelNumber.ToString());
    25. }
    26.  
    27.  
    this way we avoid the "tuningDetails = new List<TuningDetail>();"

    try catch in a loop is often costly, but only if it runs into the catch part ... try is for "free" though :)

    /gibman
     
  8. Vasilich
    • Team MediaPortal

    Vasilich Test Group

    Joined:
    August 30, 2009
    Messages:
    3,390
    Likes Received:
    608
    Gender:
    Male
    Occupation:
    Developer
    Location:
    Germany, Mayence
    Ratings:
    +1,172 / 2
    Home Country:
    Russian Federation Russian Federation
    Show System Specs
    thanks Gibman,
    use TryGetValue was my first idea, as KeyNotFoundException is known for its expense.

    Other question not directly connected ti the topic - what this code
    Code (Text):
    1.     if (detail.FreeToAir)
    2.         {
    3.           hasFta = true;
    4.         }
    5.         if (!detail.FreeToAir)
    6.         {
    7.           hasScrambled = true;
    8.         }
    9.       }
    10.  
    11.       int imageIndex;
    12.       if ([B][COLOR="Red"]hasFta && hasScrambled[/COLOR][/B])
    13.       {
    14.         imageIndex = 5;
    15.       }
    16.       else if (hasScrambled)
    17.       {
    18.         imageIndex = 4;
    19.       }
    20.       else
    21.       {
    22.         imageIndex = 3;
    23.       }
    24.  
    suppose to do? can selected condition ever be true?
    are the channels with both FTA and Scrambled flags set exist? we have in DB only one flag FreeToAir.
     
  9. mm1352000
    • Team MediaPortal

    mm1352000 Development Group

    Joined:
    September 1, 2008
    Messages:
    21,527
    Likes Received:
    4,738
    Ratings:
    +8,205 / 17
    Home Country:
    New Zealand New Zealand
    It can be the case if a channel has one or more tuning details that are FTA and one or more that are encrypted... ;)
     
  10. Vasilich
    • Team MediaPortal

    Vasilich Test Group

    Joined:
    August 30, 2009
    Messages:
    3,390
    Likes Received:
    608
    Gender:
    Male
    Occupation:
    Developer
    Location:
    Germany, Mayence
    Ratings:
    +1,172 / 2
    Home Country:
    Russian Federation Russian Federation
    Show System Specs
    just for me to get it clear: every channel can have several TuningDetails? how this supposed to work? where the information about different tuningdetails for same channel comes from? I thought when scanning every detected channel gets its own ID... or is it all about combining channels from different tuners into one?
     
  11. mm1352000
    • Team MediaPortal

    mm1352000 Development Group

    Joined:
    September 1, 2008
    Messages:
    21,527
    Likes Received:
    4,738
    Ratings:
    +8,205 / 17
    Home Country:
    New Zealand New Zealand
    You get multiple tuning details if you combine channels. This will only be relevant for some channels and for some people. I choose not to use the feature because you can't prioritise the HD sources for viewing or recording, however some people do it because it gives more scheduling flexibility. There is more chance to resolve a scheduling conflict on a channel if TV Server knows you have multiple sources for a channel...
     
Loading...

Users Viewing Thread (Users: 0, Guests: 0)

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice
  • About The Project

    The vision of the MediaPortal project is to create a free open source media centre application, which supports all advanced media centre functions, and is accessible to all Windows users.

    In reaching this goal we are working every day to make sure our software is one of the best.

             

  • Support MediaPortal!

    The team works very hard to make sure the community is running the best HTPC-software. We give away MediaPortal for free but hosting and software is not for us.

    Care to support our work with a few bucks? We'd really appreciate it!