@Jmv38 - I’ve made some bench, I was curious to see I the fastest one was the one I think.
The basic I do is take a chain of class inheritance from A to I and call a function on the last (I) that bubble up (with *.super:fn) to the root (A).
number of calls to *.super:fn = iters * (number of class inheritance - 1) - ie: 100 iters with 5 class = 400 calls to *.super:fn
== swap __index : self.super:fn() ==
5 class inheritance
> 100 iters: 0.02 sec
> 1000 iters: 0.18 sec
> 10000 iters: 1.77 sec
10 class inheritance
> 100 iters: 0.04 sec
> 1000 iters: 0.33 sec
> 10000 iters: 3.26 sec
== switch flag : self.super:fn() ==
5 class inheritance
> 100 iters: 0.01 sec
> 1000 iters: 0.18 sec
> 10000 iters: 1.79 sec
10 class inheritance
> 100 iters: 0.03 sec
> 1000 iters: 0.32 sec
> 10000 iters: 3.21 sec
== super as global : super:fn() ==
5 class inheritance
> 100 iters: 0.02 sec
> 1000 iters: 0.23 sec
> 10000 iters: 2.34 sec
10 class inheritance
> 100 iters: 0.04 sec
> 1000 iters: 0.43 sec
> 10000 iters: 4.30 sec
== no super : UpClass.fn(self) ==
5 class inheritance
> 100 iters: 0.00 sec
> 1000 iters: 0.01 sec
> 10000 iters: 0.03 sec
10 class inheritance
> 100 iters: 0.00 sec
> 1000 iters: 0.00 sec
> 10000 iters: 0.05 sec
With in mind the big overhead of properties and method access for the swap __index
and switch flag
, finaly the global super
is not so bad…