Sign in Join

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

Mailing lists / fpc-pascal / 2016-02

[PATCH] Addition of OnNotify event on "TFPGObjectList" and "TFPGList" triggered on the insert, delete and extract methods.

20 messages · 8 people · –

Reply by email Subscribe to this list Your subscription

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

Sven Barth
to silvioprog
"silvioprog" wrote
Hello, I have a friend here in Brazil that added the `notify` support to the FGL

lists, however he sented it to this Github PR [1].

I'm against that. That would negatively impact the performance of these lists.

Regards,
Sven

Reply by email

silvioprog
to Sven Barth
Sven Barth wrote 10 lines
Am 19.02.2016 12:45 schrieb "silvioprog" : > > Hello, > > I have a friend here in Brazil that added the `notify` support to the FGL lists, however he sented it to this Github PR [1]. I'm against that. That would negatively impact the performance of these lists.

As I said, please discard this PR, because I'm contacting the member (Fabiano) to use mantis instead of Github, and I received other patch from other guy (Gilson) improving this changes.

Silvio Clécio

Reply by email

Sven Barth
to silvioprog
"silvioprog" wrote
On Fri, Feb 19, 2016 at 10:24 AM, Sven Barth
Show quoted text 6 lines
> > Am 19.02.2016 12:45 schrieb "silvioprog" : > > > > Hello, > > > > I have a friend here in Brazil that added the `notify` support to the

FGL lists, however he sented it to this Github PR [1].

> > I'm against that. That would negatively impact the performance of these

lists.

As I said, please discard this PR, because I'm contacting the member

(Fabiano) to use mantis instead of Github, and I received other patch from other guy (Gilson) improving this changes.

It doesn't matter whether it is requested over here or on Mantis. I'm against adding notifications to the generic lists, because that will degrade their performance.

Regards,
Sven

Reply by email

silvioprog
to Sven Barth

On Fri, Feb 19, 2016 at 4:20 PM, Sven Barth
wrote:
[...]

It doesn't matter whether it is requested over here or on Mantis. I'm against adding notifications to the generic lists, because that will degrade their performance.

Can you send little bit sample showing this degradation? I can inform him to not send the patch because this problem. (I think that him isn't registered here in the list yet)

Silvio Clécio

Reply by email

Sven Barth
to silvioprog
"silvioprog" wrote
On Fri, Feb 19, 2016 at 4:20 PM, Sven Barth
[...] > It doesn't matter whether it is requested over here or on Mantis. I'm

against adding notifications to the generic lists, because that will degrade their performance.

Can you send little bit sample showing this degradation? I can inform him

to not send the patch because this problem. (I think that him isn't registered here in the list yet)

There's no need for a sample. This degradation is the whole reason why the non-generic classes TFPObjectList and TFPList exist compared to TObjectList and TList which do have notifications.

Regards,
Sven

Reply by email

Graeme Geldenhuys
to Sven Barth
Sven Barth wrote
There's no need for a sample. This degradation is the whole reason why the non-generic classes TFPObjectList and TFPList exist compared to TObjectList and TList which do have notifications.

I don't use Generics so it doesn't bother me either way. But purely from a software design point of view, it should be quite easy to create a list where notification can be enabled or disabled at runtime - maybe as a parameter to the constructor or via a property. On disabling notification there should be near zero degradation - at least not something noticeable.

Just my 2¢ worth.

Regards,
- Graeme -

Reply by email

Michalis Kamburelis
to Sven Barth: against adding notifications to the generic lists, because that will degrade their…
Show quoted text 7 lines
> Can you send little bit sample showing this degradation? I can inform him > to not send the patch because this problem. (I think that him isn't > registered here in the list yet) There's no need for a sample. This degradation is the whole reason why the non-generic classes TFPObjectList and TFPList exist compared to TObjectList and TList which do have notifications.

Hm, two points.

1. I'm using FGL containers a lot (because I like type-safety given by generics), and I agree that adding a notification mechanism there can slow them down. Mostly at allocation (because a deallocation is already burdened down by having to do Deref() on every item, so it would probably not suffer *so much* with unassigned OnNotify).

2. But this should not stop us from making a "generic container with notification" classes. Maybe as new classes, maybe as a boolean toggle to existing classes (as Graeme nicely suggests).

Right now we only have "with notifications, and not type-safe" containers (TObjectList/TList) and "without notifications, and type-safe using generics" containers (TFPObjectList/TFPList). But these two features (1. notifications and 2. type-safety thanks to generics) should be independent. It makes sense to create a "with notifications, and type-safe using generics" option.

So I would not reject the idea so quickly. But it indeed should be implemented carefully, without slowing down the existing TFPObjectList/TFPList.

Regards,
Michalis

Reply by email

Serguei TARASSOV
Show quoted text 19 lines
Date: Fri, 19 Feb 2016 14:01:16 +0100 From: Jonas Maebe To: FPC-Pascal users discussions Subject: Re: [fpc-pascal] Happy tickets benchmark Serguei TARASSOV wrote: > >For info, simple loop test like > > > > while i < 1000000000 do > > i := i + 1; > > > >shows that the FPC code is 2 times slower than Delphi 7 and Borland C > >5.5 and 4 times slower that C#. If that's really all there is in your program, then the C# compiler probably replaces that with "i+=1000000000;" (gcc and clang definitely will do that, I don't know about Delph 7/Borland C 5.5). This is another kind of optimisation that is seldom useful in real world programs (normally the loop will also do something useful, in which case you can't do that).

MSVC does (hence I didn't include it) but all previously listed compilers don't remove the loop.
The time ratio is about
FPC - 100, Delphi 7, Borland C - 50, C# - 25, MSVC - 0.

So my doubts was about extra-code generation for the loops.

Regards,
Serguei

Reply by email

Serguei TARASSOV
Show quoted text 6 lines
Date: Fri, 19 Feb 2016 11:49:57 -0700 (MST) From: leledumbo To: Subject: Re: [fpc-pascal] Happy tickets benchmark > >Do you have any ideas why this kind of optimization is special? Didn't Florian said that this kind of optimization has no benefit in real world programs and will only increase compilation time?

After more than 20 years in software engineering I'm avoiding to use the phrases like "real world program" or I put in quotes the word "real" at least :)

Show quoted text 15 lines
> >For info, simple loop test like > > > > while i < 1000000000 do > > i := i + 1; > > > >shows that the FPC code is 2 times slower than Delphi 7 and Borland C > >5.5 and 4 times slower that C#. Just checked such a code with gcc 5.3.0, in -O2 the generated assembly is: xorl %eax, %eax ret which literally does nothing. Without optimization the speed is equal.

It shows that gcc do the same kind of optimization as MSVC (hence I didn't include it), but other don't.
See my answer to Jonas for more details.

Regards,
Serguei

Reply by email

Serguei TARASSOV
Show quoted text 19 lines
Date: Fri, 19 Feb 2016 14:24:30 +0100 From: Sven Barth To: FPC-Pascal users discussions Subject: Re: [fpc-pascal] [PATCH] Addition of OnNotify event on "TFPGObjectList" and "TFPGList" triggered on the insert, delete and extract methods. Am 19.02.2016 12:45 schrieb "silvioprog": > > > >Hello, > > > >I have a friend here in Brazil that added the `notify` support to the FGL lists, however he sented it to this Github PR [1]. I'm against that. That would negatively impact the performance of these lists. Regards, Sven

I agree.
Actually TFPGList has already an overhead vs TList (related tests http://arbinada.com/main/en/node/1411) and it is not a good idea to increase it.
Why not simple create subclass to implement events?

Regards,
Serguei

Reply by email

Michael Van Canneyt
to Michalis Kamburelis: Hm, two points. 1. I'm using FGL containers a lot (because I like type-safety given by…
Michalis Kamburelis wrote 23 lines
>> Can you send little bit sample showing this degradation? I can inform him >> to not send the patch because this problem. (I think that him isn't >> registered here in the list yet) > > There's no need for a sample. This degradation is the whole reason why the > non-generic classes TFPObjectList and TFPList exist compared to TObjectList > and TList which do have notifications. Hm, two points. 1. I'm using FGL containers a lot (because I like type-safety given by generics), and I agree that adding a notification mechanism there can slow them down. Mostly at allocation (because a deallocation is already burdened down by having to do Deref() on every item, so it would probably not suffer *so much* with unassigned OnNotify). 2. But this should not stop us from making a "generic container with notification" classes. Maybe as new classes, maybe as a boolean toggle to existing classes (as Graeme nicely suggests). Right now we only have "with notifications, and not type-safe" containers (TObjectList/TList) and "without notifications, and type-safe using generics" containers (TFPObjectList/TFPList).

These latter 2 are not generics based. There was some experimental code which attempted to implement TFPObjectList/TFPList on top of generics, but they were slower than the native implementation. That experiment is unmaintained.

TFPGList is the one you meant, probably.

Michael.

Reply by email

denisgolovan
to Sven Barth: against adding notifications to the generic lists, because that will degrade their…

20.02.2016, 02:05, "Sven Barth" :

There's no need for a sample. This degradation is the whole reason why the non-generic classes TFPObjectList and TFPList exist compared to TObjectList and TList which do have notifications. Regards, Sven

/ My previous mail appeared to be in html format. Sorry for that.

Hi

That always keeps me wondering - why neither FPC, no any other mainstream static-type language implements specialization based not only on types, but on compile-time constants as well?

I mean something like

  TGenericList<T,options> = class
    ...
  end;

procedure TGenericList<T,options>.Delete(index:integer);
begin
  if (nnNotifyDelete in options) and Assigned(FOnDelete) then
    FOnDelete(...);
  end;
end;
// usage
type
  TMyList = specialize TGenericList<integer, [nnNotifyAdd, nnNotifyDelete, nnNotifyChange]>;

... that "if (nnNotifyDelete in options) " condition will optimized out by compiler if options lack corresponding enum constant. Of course, FOnDelete property should be omitted as well in ideal case. That might require something like "static if" in D.

I've done that trick for ages using m4 preprocessor and it works really good, why it's still not supported natively by compilers themselves?

Regards, Denis Golovan

Reply by email

Graeme Geldenhuys
to Michalis Kamburelis: Hm, two points. 1. I'm using FGL containers a lot (because I like type-safety given by…
Michalis Kamburelis wrote
So I would not reject the idea so quickly. But it indeed should be implemented carefully

And it will take 5-10 minutes to write some unit tests to see exactly what speed penalty would occur. Why guess or assume. Write some unit tests and get the facts! Then go from there.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp

Reply by email

Michalis Kamburelis
to Michael Van Canneyt: These latter 2 are not generics based. There was some experimental code which attempted…
Show quoted text 12 lines
> Right now we only have "with notifications, and not type-safe" > containers (TObjectList/TList) and "without notifications, and > type-safe using generics" containers (TFPObjectList/TFPList). These latter 2 are not generics based. There was some experimental code which attempted to implement TFPObjectList/TFPList on top of generics, but they were slower than the native implementation. That experiment is unmaintained. TFPGList is the one you meant, probably.

Ups. Yeah, by "without notifications, and type-safe using generics" containers I meant TFPGList and TFPGObjectList (and other TFPGXxx) from the FGL unit.

Regards,
Michalis

Reply by email

Sven Barth
to denisgolovan:
"denisgolovan" wrote
Hi That always keeps me wondering - why neither FPC, no any other mainstream

static-type language implements specialization based not only on types, but on compile-time constants as well?

Then you don't consider C++ as mainstream, do you?

Show quoted text 16 lines
I mean something like TGenericList<T,options> = class ... end; procedure TGenericList<T,options>.Delete(index:integer); begin if (nnNotifyDelete in options) and Assigned(FOnDelete) then FOnDelete(...); end; end; // usage type TMyList = specialize TGenericList<integer, [nnNotifyAdd,
nnNotifyDelete, nnNotifyChange]>;

I had thought about this some time ago and then found a reason why I wouldn't do it... Now if I'd only remember that reason -.-

Regards,
Sven

Reply by email

denisgolovan
to Sven Barth

21.02.2016, 02:59, "Sven Barth" :

Then you don't consider C++ as mainstream, do you? Regards, Sven

Hm. Looks like C++ actually does that and that's great. Unfortunately I stopped using C++ for large projects about 12 years ago, so my C++ template knowledge must be too old :)

I had thought about this some time ago and then found a reason why I wouldn't do it... Now if I'd only remember that reason -.-

Yes, it's interesting to see why. It's wildly useful and gives a lot of power.

Regards, Denis Golovan

Reply by email