The way this post reads to me is that MI is expensive in dynamic languages, and traits are one of many attempts to address that – that if MI were cheap, we wouldn’t need traits.
Then I failed dismally in my attempt to convey what I was trying to say :(
Yes, MI becomes rapidly unworkable in extended hierarchies.
Yes, Traits and it's kin are an attempt to reduce that complexity.
Yes, MI is expensive in dynamic langauges.
But definately NO to if MI were cheap, we wouldn’t need traits..
I did say (twice) that I am convinced that the basic issue that they are trying to address needs tackling.
What I hoped to point out is that there are many subtly different attempts at descriptions for solutions being proferred currently, but that they are concentrating on their differences--which are minutae relative to the problems of performance and footprint that they bring with them.
In compiled languages, where most of the groundwork for Traits and the others is being done, the complexities of method resolution and search order are compile time only costs. By runtime, the method call has been resolved either to a vtable entry, or to the actual entrypoint address.
Perl, (and all dynamic languages), already have a performance problem with method lookup. One of the major benefits that is hoped to come from the Parrot project is a reduction in the overheads associated with the mechanics of subroutine invokation--stack setup, scope maintenance, closure propagation, etc. If that effort succeeds, then it could reduce the costs of calling a sub to the point where static (compile time) MI would be tolorable from a performance point of view, though the inherent brain-melting problem of MI would persist.
It would also make Traits (and similar solutions) a practical solution to that MI complexity--but only if the method resolution can be fully resolved at compile-time
The fear I have is that Perl 6, and other dynamic languages that are trying to adopt trait-like behaviours, are also adding
Each of these things adds runtime cost to the process of invoking a method.
The code reads:
$obj->method();
The interpreter has to do
That's at least a two levels of indirection. One to look up the class name. One to look up the hash storing the method names associated with that classname.
If not, then look up the list of classes/traits/roles that it might inherit this method from.
Also look up classX' search pattern (depth/breadth/etc.).
For each superthing, lookup the address of it's vtable and check if it can do the method.
If not, then look up the list if it's superthings and their search patterns, and vtables and see if they can supply the method.
Keep going until you find it, or exhaust all possibilities and raise a non-existant method error.
What happens if you find two (or more) superthingies that could provide that method? Now you have to go through a conflict arbitration process.
And that lot, even with the inherent loops I've tried to indicate, is far from a complete picture of the processes involved if all the features muted for P6 come to fruition. All of that was just to find the method to invoke.
Now you have to sort out all the actual-to-formal parameter mappings, with all the
possibilities and combinations thereof.
And many of those will themselves require class hierarchy and method resolutions.
Yes, I agree that there is a complexity problem with MI that must be addressed, but I also see huge performance problems arising out of the solutions be proposed, which when combined with all the other performance sapping, runtime costs being added through the desire for even greater introspection and dynamism.
Combined, these mean that the single biggest issue I have with the current crop of dynamic language implemetations, performance--which Perl is currently the best of the bunch--is going to get worse in the next generation, not better.
In reply to Re^3: Informal Poll: why aren't you using traits?
by BrowserUk
in thread Informal Poll: why aren't you using traits?
by Ovid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |