On 2013/2/22 ro <
rayneo...@yahoo.com> wrote:
> In my implementation I indeed use two interfaces: Interface and
> InterfaceSlice. InterfaceSlice has two elements, Len and Elem. Elem returns
> the ith element, but as an interface.
> I'm sorry about my misleading statement in my previous post, it was meant to
> point out another general space inefficiency. I pass the actual array,
> because otherwise I need to do an explicit conversion to loop over the
> original array, and double (or even worse) the used memory for a while.
>
> I'm afraid I'm back on C++ for this project. Thanks so much for everyone's
> help so far.
At the moment I don't find the discussion helpful at all. You didn't
show a compilable version of your program, and your observations may
be true, but we cannot interpret them without the corresponding source
code.
> I can leave a few comments based on this experience, summarizing this
> "adventure":
> -The discussions on generics mainly focus on elegance and code duplication
> and interfaces are pointed as a potential drop-in replacement, but there is
> practical issue at hand: interface function calls cannot be inlined, this is
> inherent in their structure.
This is not true, an agressive compiler may inline interface calls in situations
where the concrete type is known. In many situations where interfaces are
used to emulate generics, it is true.
> A minor side-issue is Interfaces also require
> some extra magic with itable, function calls become even more expensive, and
> the space requirements grows with the number of functions defined in the
> interface.
The magic is extremely limited, and I don't understand your space
requirement thing.
> -Function calls (especially interface methods) are very expensive on Go. The
> first few arguments aren't passed via registers, return values are passed by
> memory, all registered are pushed onto the stack for any function call.
Yes, this is true.
> When
> this is combined with above fact, and the lack of inline assembly, doing
> high performance computations in Go can become very expensive. My
> understanding is the designers consider i/o or network latencies to be the
> minimum unit of waste, and it's probably true for what the use Go for.
> -maps are space-inefficient, hindering scalability.
High performance computation make me think of heavy array processing
using float64, but obviously you aren't talking about that.
It is not true either that contributors reason at an I/O lantency granularity.
> -The optimizer is not as good and there's no way access instructions like
> popcnt from Go, requiring some assembly code (=no inlining=function call)
> (rewriting my abelit-short CPUEater function in assembly gained me at worst
> 10x speed thanks torsqrtss and popcnt insutrctions, even at the cost of the
> interface method call BTW).
Please show the original, complete Go version of your CPUEater function.
> -And oh the "·i" redirection, which slow things about 20%.
You could have solved this by using uintptr as base type or using a
pointer receiver.
> I don't realistically think that Go will have some sort of generics some day
> (averaged over real programs, I believe cons overweigh pros), but I do hope
> that 1) the optimizer will get better 2) maps will become more space
> efficient 3) function calls will become as cheap as C function calls (at the
> expense of extra code in the compiler).
Also, remember that there are more than one Go compiler.
Rémy.