[Evaluate] optimize listview controls filling in TVSetup - Channel list for groups (2 Viewers)

mm1352000

Retired Team Member
  • Premium Supporter
  • September 1, 2008
    21,577
    8,224
    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
     

    Attachments

    • Halve_queries.patch
      1.8 KB
    • Build_dict.patch
      4.1 KB

    Vasilich

    Portal Pro
    August 30, 2009
    3,394
    1,170
    Germany, Mayence
    Home Country
    Russian Federation Russian Federation
    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.
     

    mm1352000

    Retired Team Member
  • Premium Supporter
  • September 1, 2008
    21,577
    8,224
    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
     

    gibman

    Retired Team Member
  • Premium Supporter
  • October 4, 2006
    2,998
    1,372
    Aarhus
    Home Country
    Denmark Denmark
    this is potentially an expensive call:

    Code:
     try
    +          {
    +            tuningDetails = d[channel.IdChannel];
    +          }
    +          catch (KeyNotFoundException)
    +          {
    +            tuningDetails = new List<TuningDetail>();
    +          }

    use .TryGetValue whenever possible for performance.

    Code:
    IList<TuningDetail> tuningDetails;
    if (!d.TryGetValue(channel.IdChannel, out tuningDetails) )
    {
       tuningDetails = new List<TuningDetail>();
    }

    /gibman
     

    mm1352000

    Retired Team Member
  • Premium Supporter
  • September 1, 2008
    21,577
    8,224
    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.
     

    gibman

    Retired Team Member
  • Premium Supporter
  • October 4, 2006
    2,998
    1,372
    Aarhus
    Home Country
    Denmark Denmark
    no problem..

    u can even do something like:

    Code:
    IList<TuningDetail> tuningDetails;
    bool hasTuningDetails = d.TryGetValue(channel.IdChannel, out tuningDetails);
    if (hasTuningDetails)
    {
       foreach (TuningDetail detail in tuningDetails)
              {
                if (detail.FreeToAir)
                {
                  hasFta = true;
                }
                if (!detail.FreeToAir)
                {
                  hasScrambled = true;
                }
              }
    }
    
    ...
    
    if (hasTuningDetails && tuningDetails.Count > 0)
    {
      item.SubItems.Add(tuningDetails[0].ChannelNumber.ToString());
    }

    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
     

    Vasilich

    Portal Pro
    August 30, 2009
    3,394
    1,170
    Germany, Mayence
    Home Country
    Russian Federation Russian Federation
    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:
        if (detail.FreeToAir)
            {
              hasFta = true;
            }
            if (!detail.FreeToAir)
            {
              hasScrambled = true;
            }
          }
    
          int imageIndex;
          if ([B][COLOR="Red"]hasFta && hasScrambled[/COLOR][/B])
          {
            imageIndex = 5;
          }
          else if (hasScrambled)
          {
            imageIndex = 4;
          }
          else
          {
            imageIndex = 3;
          }
    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.
     

    mm1352000

    Retired Team Member
  • Premium Supporter
  • September 1, 2008
    21,577
    8,224
    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... ;)
     

    Vasilich

    Portal Pro
    August 30, 2009
    3,394
    1,170
    Germany, Mayence
    Home Country
    Russian Federation Russian Federation
    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?
     

    mm1352000

    Retired Team Member
  • Premium Supporter
  • September 1, 2008
    21,577
    8,224
    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...
     

    Users who are viewing this thread

    Top Bottom