Efficiently calling category's pred from extending category

Help requests on developing Logtalk applications

Moderator: Paulo Moura

Post Reply
Victor NOEL
Posts: 48
Joined: Tue May 15, 2007 4:53 pm

Efficiently calling category's pred from extending category

Post by Victor NOEL » Mon May 26, 2008 3:21 pm

Hello,

After the closing of the bug report #14, a question came to my mind :

I opened the enhancement report to be able to call efficiently category's predicates from an extending category.

If I use the "::" operator to call a predicate declared in an extended category from another category, I have the feeling that it will look for it in all the inheritance tree of objects importing the category, and it will result in an inefficient call to the predicate (since I am sure that it is only declared in the category extended).

Am I wrong ? Is there another way to make this call efficiently ?

The bug report is referring to alias/2 but to me it looks like that it is only useful if the extending category is overriding a predicate from the extended category.

Thanks,

Victor

Paulo Moura
Logtalk developer
Posts: 475
Joined: Sat May 05, 2007 8:35 am
Location: Portugal
Contact:

Re: Efficiently calling category's pred from extending category

Post by Paulo Moura » Mon May 26, 2008 4:04 pm

Victor NOEL wrote: After the closing of the bug report #14, a question came to my mind :

I opened the enhancement report to be able to call efficiently category's predicates from an extending category.
The idea of a category is to act as a functionally cohesive, fine-grained unit of code reuse that can be used as component for defining objects. If you're extending a category without the explicit purpose of overriding some of its predicates (i.e. if your category does not extends the functionality of the extended category), then is probably best to reorganize your code such that your objects import all the needed categories. On the other hand, if you're calling a predicate from an extended category from within an object, you can still use the :/1 control construct. If both the imported category and the extended category are compiled separately using the reload(skip) option, you will still get performance equivalent to a call to a local object predicate (Logtalk 2.31.6, released today, fixes a bug when the :/1 control construct is used in this scenario).
Victor NOEL wrote: If I use the "::" operator to call a predicate declared in an extended category from another category, I have the feeling that it will look for it in all the inheritance tree of objects importing the category, and it will result in an inefficient call to the predicate (since I am sure that it is only declared in the category extended).
Note that the ::/1 control construct uses a caching mechanism for improved performance. However, the principal issue here is that the ::/1 control construct will take into account any predicate redefinition in the descendant objects while the :/1 control construct will ignore those redefinitions.
Victor NOEL wrote: Am I wrong ? Is there another way to make this call efficiently ?
Assuming that your question is raised in the context of the Gorgias development, I suspect that your problem will go away by re-factoring your source code. Note that my original Logtalk port of Gorgias was just a quick port to get you started; is possible that the semantics of the different Gorgias components would be better reflected by a different splitting of the original code between categories and objects.
Victor NOEL wrote: The bug report is referring to alias/2 but to me it looks like that it is only useful if the extending category is overriding a predicate from the extended category.
Correct.

Best regards,

Paulo
Paulo Moura
Logtalk developer

Victor NOEL
Posts: 48
Joined: Tue May 15, 2007 4:53 pm

Re: Efficiently calling category's pred from extending category

Post by Victor NOEL » Tue May 27, 2008 1:13 pm

Paulo Moura wrote: Note that the ::/1 control construct uses a caching mechanism for improved performance. However, the principal issue here is that the ::/1 control construct will take into account any predicate redefinition in the descendant objects while the :/1 control construct will ignore those redefinitions.
So, in practice, using :: could be efficient ?
Paulo Moura wrote: Assuming that your question is raised in the context of the Gorgias development, I suspect that your problem will go away by re-factoring your source code. Note that my original Logtalk port of Gorgias was just a quick port to get you started; is possible that the semantics of the different Gorgias components would be better reflected by a different splitting of the original code between categories and objects.
It is raised in this context, and like you said at the beginning of your answer, it is clear here that the current implementation of gorgias is not the best, and that I should think about it again :)

Thanks for your always so detailed answer :)

Victor

Paulo Moura
Logtalk developer
Posts: 475
Joined: Sat May 05, 2007 8:35 am
Location: Portugal
Contact:

Re: Efficiently calling category's pred from extending category

Post by Paulo Moura » Tue May 27, 2008 2:34 pm

Victor NOEL wrote: So, in practice, using :: could be efficient ?
The implementation of the ::/1 and ::/2 message sending control constructs use dynamic binding complemented with a cache for improved performance. The cache ensures that the lookup operations implied by sending a message (either to "self" or to another object) are only performed once (as long as the cache entries are not invalidated by subsequent operations). Of course, dynamic binding+cache will always be slower than static binding.
Victor NOEL wrote: It is raised in this context, and like you said at the beginning of your answer, it is clear here that the current implementation of gorgias is not the best, and that I should think about it again :)
If you post a description of the current Gorgias entities and their intended functionality to the Gorgias discussion thread, I will be happy to provide you with feedback on possible improvements.

Best regards,

Paulo
Paulo Moura
Logtalk developer

Victor NOEL
Posts: 48
Joined: Tue May 15, 2007 4:53 pm

Re: Efficiently calling category's pred from extending category

Post by Victor NOEL » Tue May 27, 2008 3:31 pm

Ok, I will do that : )

Thanks you

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest