Page 1 of 1
[TFindFile] Optimizing speed?

Posted:
December 3rd, 2009, 10:15 am
by ina
I am using TFindFile and it is faster if thread is used.
Do you have any idea to optimize the speed? maybe by create thread in FindFirstFile etc?
Re: [TFindFile] Optimizing speed?

Posted:
December 3rd, 2009, 10:21 am
by Kambiz
TFindFile is a bit faster when it runs in the main VCL thread (no separate thread).
Re: [TFindFile] Optimizing speed?

Posted:
December 8th, 2009, 10:38 am
by ina
Kambiz, what do you think about this code in this
linkIn that code there is:
property MaxThreads: Cardinal; protected;
Specifies the maximum number of concurrent streams.0 - no restrictions
Honestly I dont know how to use that code but can you explain me the different about your thread and that thread? If you give me sample code to use that code is better

The author's email is dead.
Re: [TFindFile] Optimizing speed?

Posted:
December 8th, 2009, 12:12 pm
by Kambiz
If you want to locate for a file in several different directories, my code uses one thread and searches the directories sequentially, but the other code searches the directories concurrently using a separate thread for each one.
Having more threads may sounds a faster search but in practice it may causes more overload because of context switching and code that is required to control the threads. If we could run each thread on a dedicated processor, then we could have a faster code.
In a system with a limited number of processors, you have to see threads as a tool to prevent blocking other part of the application, not gaining speed.
By the way, if we look for a file in a specific directory (including its sub-directories), both codes work similar.
Re: [TFindFile] Optimizing speed?

Posted:
December 29th, 2009, 7:29 am
by ina
Kambiz wrote:TFindFile is a bit faster when it runs in the main VCL thread (no separate thread).
Can you tell me exactly what I am suppose to do? Steps to modify your code to make faster? I am just a beginner
Thx.
Re: [TFindFile] Optimizing speed?

Posted:
December 29th, 2009, 7:49 am
by Kambiz
Just set Threaded property to False.
When I tell a bit faster it means about a milliseconds in searching thousands of files.
Re: [TFindFile] Optimizing speed?

Posted:
December 29th, 2009, 9:19 am
by ina
Oh I see.. but that's bad for me

Re: [TFindFile] Optimizing speed?

Posted:
December 30th, 2009, 9:01 am
by ina
Kambiz, I want to ask again

It seems your TFindFile cannot scan multiple files at the same time, for example when code enter event FindFileFileMatch, it wait for that event finished then continue the scan. Is it right? If it right, can you give me some clues to make TFindFile scan multiple files at the same time.
Re: [TFindFile] Optimizing speed?

Posted:
December 30th, 2009, 9:57 am
by Kambiz
Do you mean for example looking for C:\*.txt and C:\*.doc at the same time?
I suppose your answer is yes, otherwise correct me.
In this case, TFindFile performs a search for *.txt and then *.doc in each subfolder. As you can guess, that means two times increase in the search time. However, if you search for *.* and use filters, you can easily speed up the search.
Re: [TFindFile] Optimizing speed?

Posted:
December 30th, 2009, 11:15 am
by ina
I mean if I looking for C:\*.exe, and in FindFileFileMatch there is some routines to check the exe (may take a long time), Does TFindFile will continue for searching file or it will wait until the routines finished?
Re: [TFindFile] Optimizing speed?

Posted:
January 1st, 2010, 9:59 pm
by Kambiz
Oh, I got it now. TFindFile waits for event handlers to return.
You should initiate your own thread when processing of the matched files take a long time.
Re: [TFindFile] Optimizing speed?

Posted:
January 4th, 2010, 2:28 am
by ina
Can you give me the pseudocode or some clues?
Re: [TFindFile] Optimizing speed?

Posted:
January 4th, 2010, 3:50 am
by Kambiz
Implement your own thread class to do whatever you need on a matched file. Then create an instance of that thread when FindFile finds a file.
- Code: Select all
procedure TForm1.FindFile1FileMatch(Sender: TObject;
const FileInfo: TFileDetails);
begin
TMyThread.Create(FileInfo);
end;