Using madExcept seems to slow down my app

delphi package - automated exception handling
Post Reply
csterg
Posts: 4
Joined: Thu Jan 05, 2006 3:27 pm

Using madExcept seems to slow down my app

Post by csterg »

Hello,
i have been testing the madExcept package along with the FastMM4. It seems that when i use madExcept, the app is being slowed down about 10% (almost the gain i have from FastMM4).
Why is this?
Does madExcept play around with the Memory Manager? Does it use it's own MM?
Thanks
Costas
Last edited by csterg on Mon Jan 09, 2006 8:58 am, edited 1 time in total.
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

madExcept doesn't use it's own MM nor does it play around with the memory manager. There are 2 things in madExcept which may affect performance:

(1) Using "RegisterHiddenExceptionHandler" costs performance.
(2) The creation and termination of new threads costs a little bit performance, but not much.

Do you have a simple test project with which I can check the performance problems you're seeing?

Thanks...
csterg
Posts: 4
Joined: Thu Jan 05, 2006 3:27 pm

Post by csterg »

Thanks for your fast response: i was expecting to be notified of it by email but somehow i didn't get it so i am back 3 days later... sorry (and i was anxious for the response :))

Anyway, let me paste a small example here:
madshi wrote: Do you have a simple test project with which I can check the performance problems you're seeing?
Thanks...
Test project:

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var
  now: Cardinal;
  s: TStringList;
  i: Integer;
begin
  now := GetTickCount;
  for i:=0 to 1000000 do begin
    s := TStringList.Create;
    s.Add('test');
    s.Free;
  end;
  ShowMessage(IntToStr(GetTickCount-now));
end;
Results (2GHz PC):
Default MM, no madExcept: 1250ms
Default MM, with madExcept: 2550ms
FastMM4, no madExcept: 920ms
FastMM4, with madExcept: 1250ms

In all cases there is optimization and no checks.

Thanks,
Costas
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

I've just checked out the situation and the reason for the speed loss is quite simple. Try this code *without* madExcept:

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var
  now: Cardinal;
  s: TStringList;
  i: Integer;
begin
  IsMultiThread := true;
  now := GetTickCount;
  for i:=0 to 1000000 do begin
    s := TStringList.Create;
    s.Add('test');
    s.Free;
  end;
  ShowMessage(IntToStr(GetTickCount-now));
end;
csterg
Posts: 4
Joined: Thu Jan 05, 2006 3:27 pm

Post by csterg »

Well, i see EXACTLY your point: never thought of that :)
As I understand, madExcept creates an additional thread (for watching) and this sets the IsMultiThread var (in TThread class?), so when i use the madExcept i have the nominal overhead that comes in memory management for multi-threaded apps.

OK, this is perfectly acceptable and understandable: it is very good though that FastMM4 has a 50% increase in these cases (multi-threaded apps), so for multi-threaded apps there is no real 'penalty' for using madExcept (and FastMM4 really compensates in these cases).

Costas
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Yes, you got it right. madExcept doesn't cost performance. However, madExcept switches the memory manager to multi threading mode and that is what costs performance.
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

P.S: Honestly, I was not really aware of this. I naively thought all (or at least most) programs today would be using multiple threads, anyway... :) But I have to admit, there are probably a lot of programs not using any threads. And madExcept will then cost performance because of the IsMultiThread stuff. But well, there's nothing I can do about that, since madExcept absolutely does need threads.
csterg
Posts: 4
Joined: Thu Jan 05, 2006 3:27 pm

Post by csterg »

Well, this is how the combination of madExcept with FastMM4 can persuade even those that build single-threaded apps that madExcept really 'costs' nothing in terms of performance. But the penalty otherwise, is quite big (about doubling the response).
Anyway, a big thanks for this awesome product which really does a terrific job!
Costas
Post Reply