Another GetDirectory/My Videos Slow Display (1 Viewer)

Q

Q3aiml

Guest
On My Movies with ~400+ files (stacking disabled) it takes a noticeable 3-4 seconds to list. I think there is an easy solution involving GetDirectory and SetThumbnails.

  • Create a duplicate SetThumbnails copied from the first one, for testing I just named it SetThumbnailsTest.
  • Change SetThumbnailsTest to also accept a string[] files as an argument
  • For the three IO.File.Exists run a BinarySearch on the files arg instead (Don't edit the one after GetThumb or if it is a folder). So (System.IO.File.Exists(strThumb)) -> (Array.BinarySearch(test, strThumb) < 0)
  • Update the call in GetDirectory used under IsValidExtension while enumerating files in the directory to call the new function, passing strFiles as the second argument

For me this reduced listing time to under one second, still noticeable but alot better.

I have only been looking at the source for about three hours, and have never programmed C# prior in my life, so if what I did simply breaks the function feel free to flame me. I have tested it, so i'm only worried about it not showing the thumbnails correctly - like if I changed what the function actually did.

Anyways hope that helps

Edit: Feel free to lynch me for not using the handy dandy template.
 

dman_lfc

Retired Team Member
  • Premium Supporter
  • July 28, 2004
    1,772
    30
    UK
    Home Country
    New Zealand New Zealand
    Moved to General Development from Bugs as its not a bug, just the coding could be more efficient.

    And thanks for the tips - I'm sure Frodo will look at it and advise.

    DMAN
     
    Q

    Q3aiml

    Guest
    Edit: Ignore suggested fix in this post. Speed improvement was based upon chance.

    Ooo I think I found the last major bottleneck. IsValidExtensions is using a foreach *ouch* to compare m_extensions. Also inside on each iteration we we are using ToLower on the same input.

    This fix assumes that m_extensions is already lowercase. If not then we should make it lowercase at the time it is being set. Anyways change
    Code:
    string strExtFile = System.IO.Path.GetExtension(strPath);
    foreach (string strExt in m_extensions)
    {
    	if (strExt.ToLower() == strExtFile.ToLower()) return true;
    }
    to
    Code:
    if (m_extensions.BinarySearch(strExtFile.ToLower()) >= 0) return true;

    and for me what took 800ms goes to 50ms.
     
    Q

    Q3aiml

    Guest
    Hey Frodo, found out the source of the problem. BinarySearch assumes a sorted list, so it was only by chance that the order allowed it to work in My Videos but not Pictures.

    Fix:
    Code:
    public void SetExtensions(ArrayList extensions)
    {
         if (extensions==null) return;
         m_extensions = extensions;
         m_extensions.Sort();
    }
    Code:
    public void AddExtension(string strExtension)
    {
         if (m_extensions == null)
              m_extensions = new ArrayList();
         m_extensions.Add(strExtension);
         m_extensions.Sort();
    }

    Unfortunately now any speed improvements are lost. Scratch this as an improvement.
     

    Users who are viewing this thread

    Top Bottom