[Vala] Unexpected behaviour when using interfaces.



Hi list.
This is my first time posting here, so bare with me if I'm being an idiot.

I apologize for continuing with the performance discussion but I've noticed
unintuitive (at least to me) behaviour when using interfaces in Vala.

I know that calling interface methods is expensive and that it's a known issue
in GLib but there is another problem. When a class implements an interface,
calling methods is slow regardless whether you declare your objects as being
instances of the class or the interface.

I attached a simple example that demonstrates the problem.
Object1 implements the interface directly and it doesn't matter whether we
declare our object as Interface or Object1, both are slow.

Object1 through interface : 18.620215
Object1 directly          : 18.767607

Object2 does not implement Interface directly but inherits form AbsObject
(which in this case is abstract but it could also be a regular class). which in
turn implements Interface, now only the instance declared as Interface is slower.

Object2 through interface : 18.902430
Object2 directly          : 2.987541

Looking at the generated C code it seems to be a side effect of the way vala
handles inheritance but I don't have enough experience with GObject to judge.

So my question would be whether this is intentional, maybe I'm missing something?
If it is then interfaces have to be used even more carefully and you need to use
a dummy class in between the interface just to be able to use your class without
the extra overhead when the interface is not needed.

Regards, Sergej

Attachment: interface-test.vala
Description: Text Data



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]