unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Mark H Weaver <mhw@netris.org>
To: Daniel Llorens <daniel.llorens@bluewin.ch>
Cc: guile-devel@gnu.org
Subject: Re: vectors are something else
Date: Mon, 15 Apr 2013 22:00:55 -0400	[thread overview]
Message-ID: <87haj72q08.fsf@tines.lan> (raw)
In-Reply-To: <9D053760-46BC-46F1-B84D-07902E777FF2@bluewin.ch> (Daniel Llorens's message of "Mon, 15 Apr 2013 13:29:23 +0200")

Daniel Llorens <daniel.llorens@bluewin.ch> writes:

> Date: Fri, 12 Apr 2013 17:43:14 -0400
> From: Mark H Weaver <mhw@netris.org>
>
>> I've not yet had time to carefully read this thread, but I wanted to say
>> that I think we *should* prohibit passing arrays to the vector
>> interfaces.  When we have native code generation, then it will be
>> possible to make the vector procedures extremely simple machine code
>> sequences.  We must avoid adding any complications to this.  Even a
>> single additional conditional branch will be painful, in both runtime
>> overhead and code size.
>> 
>> If we were to support a subset of arrays to the vector interface, the
>> way it should be done is have the array constructors produce actual
>> vector objects when possible, or at least something that can be used by
>> the simple vector code sequences without any additional conditional
>> branches.
>> 
>> Does this make sense?
>
> Two things about this.
>
> First, arrays cannot remain opaque types if we want any kind of
> performance. The compiler should know about the storage and about the
> array descriptor as independent objects. Then it's possible to inline
> the index computations, or to eliminate the array descriptor whenever
> it is not used or when its fields are known at compile time, or to
> eliminate type checks.

Unfortunately, this is rarely possible in a language like Scheme, where
calls to procedures bound by mutable top-level variables are frequent.
We cannot fix this without making most commonly-used top-level bindings
immutable.  Last I checked, there was strong resistance to this idea.

> Second, the array operations don't involve any more branching than the
> vector operations, only an extra indirection that can be amortized
> over the size of the vector.

The cost can only be amortized in cases where the entire loop over the
vector is done without any calls to procedures bound by mutable
variables.

> That's why I think that there're two options:
>
> [1] have vector- ops only accept vector- types. This removes container
> type dispatch from the vector- ops but not from the array- ops. The
> last patch set I've sent to the list goes in this direction. It
> matches the behavior of other vector-like types such as bytevectors
> and strings.

I very much favor this approach, but unfortunately I don't think we can
do it in 2.0.  It'll have to wait until 2.2.

> [2] force all vector objects into arrays. This removes container type
> dispatch from both the vector- and the array- ops, but it adds the
> cost of indirection to the vector- ops. Which is, I think, a good
> tradeoff, because that cost is smaller, there's some hope that the
> compiler will remove it in many cases, and we retain the flexibility
> in the use of vectors that we have now.

I consider this option completely unacceptable.  Arrays are much more
complex than vectors, and will inevitably be *much* slower in the common
case where the compiler doesn't know much.  Most egregiously,
'make-shared-array' requires that array references apply an arbitrary
affine transformation that's unknown at compile time, which means
multiplications and additions for each index.

Don't get me wrong: I'm all in favor of providing flexible, generic,
extensible procedures.  They have their place.  I think that's why
there's still a justification for keeping 'generalized-vectors' around.
However, efficiency demands that we also have simple, non-generic,
non-extensible procedures as well.  IMO, we should keep the vector,
bitvector, and bytevector procedures as simple as possible.

Does this make sense?  More thoughts?

Thanks for your work on this.

      Mark



  parent reply	other threads:[~2013-04-16  2:00 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.1288755.1365813667.854.guile-devel@gnu.org>
2013-04-15 11:29 ` vectors are something else Daniel Llorens
2013-04-15 12:28   ` Daniel Hartwig
2013-04-15 14:08     ` Daniel Llorens
2013-04-15 14:17       ` Daniel Hartwig
2013-04-15 14:10     ` vector types poll Daniel Llorens
2013-04-15 22:47       ` Daniel Hartwig
2013-04-16  0:16         ` Daniel Llorens
2013-04-16  2:00   ` Mark H Weaver [this message]
2013-04-16  4:10     ` vectors are something else Daniel Llorens
2013-04-16  6:19       ` Mark H Weaver
2013-04-16  8:31         ` Daniel Llorens
2013-04-17 15:29     ` Mutable top-level bindings (was: vectors are something else) Chris K. Jester-Young
2013-04-17 17:53       ` Mutable top-level bindings Mark H Weaver
2013-04-17 20:25       ` Ian Price
2013-04-20 14:00       ` Ludovic Courtès
     [not found] <mailman.197.1365782461.8676.guile-devel@gnu.org>
2013-04-12 23:12 ` vectors are something else Daniel Llorens
     [not found] <mailman.1287634.1365761713.854.guile-devel@gnu.org>
2013-04-12 12:37 ` Daniel Llorens
2013-04-12 14:06   ` Daniel Hartwig
2013-04-13  0:40   ` Daniel Llorens
2013-04-10 23:07 Daniel Llorens
2013-04-11  7:29 ` Daniel Llorens
2013-04-11 23:53 ` Daniel Hartwig
2013-04-12  7:23   ` Daniel Llorens
2013-04-12 10:15     ` Daniel Hartwig
2013-04-12 10:41       ` Daniel Hartwig
2013-04-12 21:43       ` Mark H Weaver

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87haj72q08.fsf@tines.lan \
    --to=mhw@netris.org \
    --cc=daniel.llorens@bluewin.ch \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).