I would have used this in one of my programs. I converted a core
recursion to a self managed combination of return stack and gotos for
a 34% speedup. My stack has three variables that I need to restore
before the goto on each "return." I tried many different ways of
coding the push and the pop: as an array of structures with three
values, as three arrays of values, etc. The performance in each case
is limited by either the cost of the array bounds test (either one or
three) or the cost of the packing and unpacking of the structure
(three assignments or structure assignment of a struct literal. The
three cases are:

sp := &exact.stack[k]
columns = sp.columns
c = sp.c
r = sp.r

columns = exact.stack[k].columns
c = exact.stack[k].c
r = exact.stack[k].r

The uncommented version is the fastest by far. The braces are needed
to help the compiler handle register pressure; the code is 2% slower
without them. What I wanted was this:

columns, c, r = destructure(exact.stack[k])

which would let the compiler do one array bounds check, one index
operation, and three direct moves. But I did not ask for it. I always
seem to be asking for things that nobody else wants. For example, I
would not put shaving a microsecond from the compile time above
forcing programmers to try an exponential number of brace
installations to manual show variable lifetimes. ;-)
On Thu, Nov 1, 2012 at 4:19 AM, minux wrote:
On Thu, Nov 1, 2012 at 6:50 PM, Peter wrote:

I agree with Kevin. I can't see how I would need this feature (I haven't
so far, anyway). How often do you return a variable number of arguments and
don't want a slice? Why wouldn't you want a slice?
tuples are useful because it can contain different types of objects (unlike
strict typing
arrays and slices).

and i think the main usage for tuples is to compensate the lack of multiple
return values.

Go does have support for multiple return values, so i think one large use
case of tuples
is gone.


Michael T. Jones | Chief Technology Advocate | mtj@google.com | +1


Search Discussions

Discussion Posts


Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 14 of 22 | next ›
Discussion Overview
groupgolang-nuts @
postedOct 31, '12 at 9:15a
activeNov 2, '12 at 7:51a



site design / logo © 2021 Grokbase