[TFindFile] Optimizing speed?

Please post bug reports, feature requests, or any question regarding the DELPHI AREA products here.

[TFindFile] Optimizing speed?

Postby ina » December 3rd, 2009, 10:15 am

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?
ina
Active Member
Active Member
 
Posts: 14
Joined: November 24th, 2009, 4:34 pm

Re: [TFindFile] Optimizing speed?

Postby Kambiz » December 3rd, 2009, 10:21 am

TFindFile is a bit faster when it runs in the main VCL thread (no separate thread).
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Re: [TFindFile] Optimizing speed?

Postby ina » December 8th, 2009, 10:38 am

Kambiz, what do you think about this code in this link
In 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.
ina
Active Member
Active Member
 
Posts: 14
Joined: November 24th, 2009, 4:34 pm

Re: [TFindFile] Optimizing speed?

Postby Kambiz » December 8th, 2009, 12:12 pm

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.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Re: [TFindFile] Optimizing speed?

Postby ina » December 29th, 2009, 7:29 am

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.
ina
Active Member
Active Member
 
Posts: 14
Joined: November 24th, 2009, 4:34 pm

Re: [TFindFile] Optimizing speed?

Postby Kambiz » December 29th, 2009, 7:49 am

Just set Threaded property to False.

When I tell a bit faster it means about a milliseconds in searching thousands of files.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Re: [TFindFile] Optimizing speed?

Postby ina » December 29th, 2009, 9:19 am

Oh I see.. but that's bad for me 8-[
ina
Active Member
Active Member
 
Posts: 14
Joined: November 24th, 2009, 4:34 pm

Re: [TFindFile] Optimizing speed?

Postby ina » December 30th, 2009, 9:01 am

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.
ina
Active Member
Active Member
 
Posts: 14
Joined: November 24th, 2009, 4:34 pm

Re: [TFindFile] Optimizing speed?

Postby Kambiz » December 30th, 2009, 9:57 am

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.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Re: [TFindFile] Optimizing speed?

Postby ina » December 30th, 2009, 11:15 am

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?
ina
Active Member
Active Member
 
Posts: 14
Joined: November 24th, 2009, 4:34 pm

Re: [TFindFile] Optimizing speed?

Postby Kambiz » January 1st, 2010, 9:59 pm

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.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm

Re: [TFindFile] Optimizing speed?

Postby ina » January 4th, 2010, 2:28 am

Can you give me the pseudocode or some clues?
ina
Active Member
Active Member
 
Posts: 14
Joined: November 24th, 2009, 4:34 pm

Re: [TFindFile] Optimizing speed?

Postby Kambiz » January 4th, 2010, 3:50 am

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;
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2408
Joined: March 7th, 2003, 7:10 pm


Return to DELPHI AREA Products

Who is online

Users browsing this forum: No registered users and 1 guest

cron