ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Performance when loading images using threads.

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
JimMellish Posted - Apr 26 2018 : 06:15:44
I have found that when loading dng files there is no performance increase when using threads.

I am using the following code to test the perfomance without and with threads:

  Vec := TDirectory.GetFiles ('D:\Old Drive F\Photographs\Digital\Temp');

  { Without thread }
  for i := 0 to Length(Vec) - 1 do
    begin
      View := TImageEnView.Create(nil);
      try
        View.IO.LoadFromFile(Vec[i]);
      finally
        View.Free;
      end;
    end;

  { With thread }
  TParallel.For (0, Length(Vec) - 1,
    procedure (i: integer)
    var v: TImageEnView;
    begin
      v := TImageEnView.Create(nil);
      try
        v.IO.LoadFromFile(Vec[i]);
      finally
        v.Free;
      end;
    end);

For 180 jpg files my test went from 48 secs down to 10 secs and cpu usage increased from 20% to 95%.
For 20 dng files my test went from 61 secs down to 59 secs and cpu usage remained at about 20%.

In both cases my memory usage was about 28% and disk usage about 5%.

Digging further I found that the dng files are loaded using a dll. Could this be the cause ? Is there any was I can speed up loading raw files ?

3   L A T E S T    R E P L I E S    (Newest First)
JimMellish Posted - Apr 30 2018 : 05:46:23
Hi Nigel

I have done further testing and the result is confusing. For these tests I was always running without the debugger.

My desktop is running Windows 10, Delphi 10.1 with an older AMD processor.

Switching to LibRaw did seem to make a difference but it was very very unstable with the TParallel.For loop throwing exceptions most of the time. Turning LibRaw off, running the program, turning LibRaw on, running the program did not stop the exceptions. Even closing Delphi and starting it again did not stop the exceptions. I could not work out a series of steps to take to get which would always allow the program to run without exceptions.

I also tried using OmniThreadLibrary Parallel.For. In this case no exceptions were generated. However, the task manager would show the processor usage going from 100% down to 1% or 2% implying that the parallel tasks had finished but control never returned to the main thread.

My Laptop is running Windows 10 Delphi 10.2.3 with just ImageEn and OmniThreadLibrary installed. It has an older Intel processor. LibRaw did make a difference and I could see the processor usage hitting 100%. Here are the results:

No parallel tasks: 31.777 secs
Delphi TParallel.For: 16.911 secs
OmnithreadLibrary Parallel.For: 16.867

The program ran reliably with no exceptions generated.

Jim
xequte Posted - Apr 26 2018 : 19:27:54
Hi

I cannot see any reason the DLL itself should affect it, but is may be something due to dcraw.

Does changing to LibRaw make any difference:

https://www.imageen.com/help/TIEImageEnGlobalSettings.UseLibRaw.html

Nigel
Xequte Software
www.imageen.com
PStadler Posted - Apr 26 2018 : 09:20:17
Hello,

I wrote a program from your source above, I post here.


unit ImageEnThread_Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Menus;

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    RunwithoutThread1: TMenuItem;
    RunwithThread1: TMenuItem;
    withoutThread1: TMenuItem;
    procedure RunWithoutThread1Click(Sender: TObject);
    procedure RunWithThread1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
    procedure LoadImagesWithoutThread;
    procedure LoadImagesWithThread;
    procedure GetImageList;
  end;

var
  Form1: TForm1;

implementation

uses
  ImageEnView,
  System.Threading,
  System.IOUtils,
  System.Types,
  IEMView;

{$R *.dfm}


var
  Vec : TStringDynArray;
  ImageEnMView1 : TImageEnMView;


 procedure TForm1.FormCreate(Sender: TObject);
begin
  GetImageList;
end;

procedure TForm1.GetImageList;
 begin
    Vec := TDirectory.GetFiles (path);
 end;



  { Without thread }
procedure TForm1.LoadImagesWithoutThread;
var
  i  : Cardinal;
  View : TImageEnView;
begin
  for i := 0 to Length(Vec) - 1 do
  begin
    View := TImageEnView.Create(nil);
    try
    View.IO.LoadFromFile(Vec[i]);
    finally
    View.Free;
   end;
  end;
end;

 { With thread }
procedure TForm1.LoadImagesWithThread;
var
  i  : Cardinal;
  View : TImageEnView;
begin
 
  TParallel.For (0, Length(Vec) - 1,
    procedure (i: integer)
    var View: TImageEnView;
    begin
      View := TImageEnView.Create(nil);
      try
      View.IO.LoadFromFile(Vec[i]);
      finally
      View.Free;
    end;
  end);
end;

procedure TForm1.RunWithoutThread1Click(Sender: TObject);
begin
  LoadImagesWithoutThread;
end;

procedure TForm1.RunWithThread1Click(Sender: TObject);
begin
  LoadImagesWithThread;
end;


end.


I can reproduce the speed of loading pngs 10 times faster than without threads, but the images are not shown. What is wrong?

Sincerely Peter