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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Performance when loading images using threads.
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

JimMellish

United Kingdom
7 Posts

Posted - Apr 26 2018 :  06:15:44  Show Profile  Reply
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 ?

PStadler

Austria
60 Posts

Posted - Apr 26 2018 :  09:20:17  Show Profile  Reply
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
Go to Top of Page

xequte

38189 Posts

Posted - Apr 26 2018 :  19:27:54  Show Profile  Reply
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
Go to Top of Page

JimMellish

United Kingdom
7 Posts

Posted - Apr 30 2018 :  05:46:23  Show Profile  Reply
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
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: