Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2002-05

raise's exceptaddr

12 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Aleksey V. Vaneev

Hello,

Could you implement a dedicated exceptaddr frame creation for raise statements? Because now if raise uses some ansistring constructor, it automatically creates exception frame for the whole procedure where raise was placed. But in most cases exception is not raised and exception frame becames a burden for the whole procedure, especially if ansistrings generally were not used.

Right now I have a "on-the-knee" solution - I'm just creating a local subprocedure called like "doraise" that just raises an exception. This way exception frame is not created in the main procedure, but is created "in time" when the exception raise is needed.

This is maybe not a "general case optimisation", but it is an obvious way to sped up things if exceptions were used.

Best regards,
Aleksey

Reply by email

Michael Van Canneyt
to Aleksey V. Vaneev
Aleksey V. Vaneev wrote 8 lines
Hello, Could you implement a dedicated exceptaddr frame creation for raise statements? Because now if raise uses some ansistring constructor, it automatically creates exception frame for the whole procedure where raise was placed. But in most cases exception is not raised and exception frame becames a burden for the whole procedure, especially if ansistrings generally were not used.

The frame will always be created. As soon as ansistrings is used in a procedure, an exception frame is created in a procedure - always. Even is no raise statement is present (an exception could e.g. be raised in a called procedure).

Michael.

Reply by email

Aleksey V. Vaneev

Hello,

Show quoted text 6 lines
The frame will always be created. As soon as ansistrings is used in a procedure, an exception frame is created in a procedure - always. Even is no raise statement is present (an exception could e.g. be raised in a called procedure). Michael.

I think you have not got the idea.

I mean, if I write something like this:

resourcestring
  ErrMsg = 'aaabbbccc';
procedure Test123;
begin
     if (not Success) then
       raise Exception.create (ErrMsg);
    ...do something a little...
end;

Stackframe will be created for the whole Test123 and its overhead will be applied to "...do something a little..." in all the cases.

But if I write in this way:

procedure Test123;
  procedure doraise;
  begin
    raise Exception.create (ErrMsg);
  end;
begin
     if (not Success) then
       doraise;
    ...do something a little...
end;

Overhead is issued ONLY if Success = False. In all other cases "...do something a little..." executes without ANY unnecessary overhead.

Best regards,
Aleksey

Reply by email

Florian Klaempfl
to Michael Van Canneyt: The frame will always be created. As soon as ansistrings is used in a procedure, an…
you wrote 10 lines
On Fri, 3 May 2002, Aleksey V. Vaneev wrote: > Hello, > > Could you implement a dedicated exceptaddr frame creation for raise > statements? Because now if raise uses some ansistring constructor, > it automatically creates exception frame for the whole procedure > where raise was placed. But in most cases exception is not raised > and exception frame becames a burden for the whole procedure, > especially if ansistrings generally were not used.

I see your point, but implementing this especially for raise seems to require a lot of effort and the speed gain will be little ... especially because the 1.1 compiler has an optimized exception frame handling.

The frame will always be created. As soon as ansistrings is used in a procedure, an exception frame is created in a procedure - always. Even is no raise statement is present (an exception could e.g. be raised in a called procedure).

Hmmm, please reread the quoted original email, Michael :)!

Reply by email

Unknown author
to Aleksey V. Vaneev: I think you have not got the idea. I mean, if I write something like this: resourcestring…
Aleksey V. Vaneev wrote 45 lines
Hello, > The frame will always be created. As soon as ansistrings is used > in a procedure, an exception frame is created in a procedure - > always. Even is no raise statement is present (an exception could > e.g. be raised in a called procedure). > > Michael. I think you have not got the idea. I mean, if I write something like this: resourcestring ErrMsg = 'aaabbbccc'; procedure Test123; begin if (not Success) then raise Exception.create (ErrMsg); ...do something a little... end; Stackframe will be created for the whole Test123 and its overhead will be applied to "...do something a little..." in all the cases. But if I write in this way: procedure Test123; procedure doraise; begin raise Exception.create (ErrMsg); end; begin if (not Success) then doraise; ...do something a little... end; Overhead is issued ONLY if Success = False. In all other cases "...do something a little..." executes without ANY unnecessary overhead.

OK, I see what you mean now, yes, in this case the code will be faster. I'm not sure whether this is possible, this is something for Florian Klaempfl to decide :/

Michael.

Reply by email

Unknown author
to Florian Klaempfl: I see your point, but implementing this especially for raise seems to require a lot of…
Florian Klaempfl wrote 25 lines
At 11:02 15.05.02 +0200, you wrote: >On Fri, 3 May 2002, Aleksey V. Vaneev wrote: > > > Hello, > > > > Could you implement a dedicated exceptaddr frame creation for raise > > statements? Because now if raise uses some ansistring constructor, > > it automatically creates exception frame for the whole procedure > > where raise was placed. But in most cases exception is not raised > > and exception frame becames a burden for the whole procedure, > > especially if ansistrings generally were not used. I see your point, but implementing this especially for raise seems to require a lot of effort and the speed gain will be little ... especially because the 1.1 compiler has an optimized exception frame handling. >The frame will always be created. As soon as ansistrings is used >in a procedure, an exception frame is created in a procedure - >always. Even is no raise statement is present (an exception could >e.g. be raised in a called procedure). Hmmm, please reread the quoted original email, Michael :)!

Yes. I misunderstood what he wanted to say :/

Michael.

Reply by email

Peter Vreman
Show quoted text 53 lines
On Thu, 16 May 2002, Aleksey V. Vaneev wrote: > Hello, > > > The frame will always be created. As soon as ansistrings is used > > in a procedure, an exception frame is created in a procedure - > > always. Even is no raise statement is present (an exception could > > e.g. be raised in a called procedure). > > > > Michael. > > I think you have not got the idea. > > I mean, if I write something like this: > > resourcestring > ErrMsg = 'aaabbbccc'; > > procedure Test123; > begin > if (not Success) then > raise Exception.create (ErrMsg); > > ...do something a little... > end; > > Stackframe will be created for the whole Test123 and its overhead will be > applied to "...do something a little..." in all the cases. > > But if I write in this way: > > procedure Test123; > > procedure doraise; > begin > raise Exception.create (ErrMsg); > end; > > begin > if (not Success) then > doraise; > > ...do something a little... > end; > > Overhead is issued ONLY if Success = False. In all other cases "...do > something a little..." executes without ANY unnecessary overhead. OK, I see what you mean now, yes, in this case the code will be faster. I'm not sure whether this is possible, this is something for Florian Klaempfl to decide :/

But what when you have:

case value of
1 :
ansistring operation
2 :
ansistring operation
3 :
ansistring operation
else
shortstring operation
end;

Then with having the exceptionframe around the smallest possible ansistring operation it will generate the code 3 times.

Reply by email

Florian Klaempfl
to Peter Vreman
you wrote 70 lines
> > > On Thu, 16 May 2002, Aleksey V. Vaneev wrote: > > > Hello, > > > > > The frame will always be created. As soon as ansistrings is used > > > in a procedure, an exception frame is created in a procedure - > > > always. Even is no raise statement is present (an exception could > > > e.g. be raised in a called procedure). > > > > > > Michael. > > > > I think you have not got the idea. > > > > I mean, if I write something like this: > > > > resourcestring > > ErrMsg = 'aaabbbccc'; > > > > procedure Test123; > > begin > > if (not Success) then > > raise Exception.create (ErrMsg); > > > > ...do something a little... > > end; > > > > Stackframe will be created for the whole Test123 and its overhead will be > > applied to "...do something a little..." in all the cases. > > > > But if I write in this way: > > > > procedure Test123; > > > > procedure doraise; > > begin > > raise Exception.create (ErrMsg); > > end; > > > > begin > > if (not Success) then > > doraise; > > > > ...do something a little... > > end; > > > > Overhead is issued ONLY if Success = False. In all other cases "...do > > something a little..." executes without ANY unnecessary overhead. > > OK, I see what you mean now, yes, in this case the code will be faster. > I'm not sure whether this is possible, this is something for Florian > Klaempfl to decide :/ But what when you have: case value of 1 : ansistring operation 2 : ansistring operation 3 : ansistring operation else shortstring operation end; Then with having the exceptionframe around the smallest possible ansistring operation it will generate the code 3 times.

It would need some addtional information:
When compiled with -OG it would be worth the effort in this case.

Nevertheless, it would require heavy changes in temp. ansistring generation and raise
code generation, so Aleksey's workround seems to me the only solution.

Reply by email

Aleksey V. Vaneev

Hello,

Show quoted text 15 lines
But what when you have: case value of 1 : ansistring operation 2 : ansistring operation 3 : ansistring operation else shortstring operation end; Then with having the exceptionframe around the smallest possible ansistring operation it will generate the code 3 times.

I'm not talking about such cases. I meant only RAISE statement, because its usage denotes an exceptional program's behaviour that is generally rare. And BTW, "case" example you've mentioned if you apply strategy I've proposed will be slow only in loops.

Anyways, I think there is some research needed in this field - optimising stackframes insertion will obviously give a general speedup.

But anyways, "raise" optimisation could be very useful. (in fact, I'm forced to use doraise; procs now, but this is VERY unpleasant).

Best regards,
Aleksey

Reply by email

Florian Klaempfl
to Aleksey V. Vaneev
you wrote 26 lines
Hello, > But what when you have: > > case value of > 1 : > ansistring operation > 2 : > ansistring operation > 3 : > ansistring operation > else > shortstring operation > end; > > Then with having the exceptionframe around the smallest possible ansistring operation it > will generate the code 3 times. I'm not talking about such cases. I meant only RAISE statement, because its usage denotes an exceptional program's behaviour that is generally rare. And BTW, "case" example you've mentioned if you apply strategy I've proposed will be slow only in loops. Anyways, I think there is some research needed in this field - optimising stackframes insertion will obviously give a general speedup.

I totally agree with you but as you may know there are a lot of other things which must be done, so this optimization is postboned by use except somebody provides patch to implement it :/

Show quoted text 11 lines
But anyways, "raise" optimisation could be very useful. (in fact, I'm forced to use doraise; procs now, but this is VERY unpleasant). Best regards, Aleksey _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email