unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* goops speedups
@ 2020-10-10 15:16 Stefan Israelsson Tampe
  2020-10-10 20:12 ` Linus Björnstam
  0 siblings, 1 reply; 2+ messages in thread
From: Stefan Israelsson Tampe @ 2020-10-10 15:16 UTC (permalink / raw)
  To: Guile User

Dear all,

Consider the following code

(define (f x)
   (let lp ((i 0) (s 0))
       (if (< i (len x))
           (lp (+ i 1) (+ (get x i) s))
           s)))

Not an uncommon code. The problem is you should be able speed up the loop
if len and get is generalized procedures by doing the dispatch once like
this

(define (f x)
   (let ((-len (find-dispatch len x))
          (-get (find-dispatch get x)))
     (let lp ((i 0) (s 0))
         (if (< i (-len x))
             (lp (+ i 1) (+ (-get x i) s))
              s))))

The question is if we have such an interface or similar or if we should
request that we get such a feature from the guile overlords.

Regards
Stefan


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: goops speedups
  2020-10-10 15:16 goops speedups Stefan Israelsson Tampe
@ 2020-10-10 20:12 ` Linus Björnstam
  0 siblings, 0 replies; 2+ messages in thread
From: Linus Björnstam @ 2020-10-10 20:12 UTC (permalink / raw)
  To: Stefan Israelsson Tampe, Guile User

Good idea. However: There are loads of data structures that don't do efficient random access. Lists, of course, but also fectors, where going down the tree on each element access has a lot higher overhead than going through it sequentially. A generator based approach to iterating through them would potentially be more efficient for the case when you want to go from 0..((find-dispatch len x) x).

Guile lacks srfi-158, bit the reference implementation should run with no or very minor fixes. The coroutine generators should be done using delimited continuations though.
-- 
  Linus Björnstam

On Sat, 10 Oct 2020, at 17:16, Stefan Israelsson Tampe wrote:
> Dear all,
> 
> Consider the following code
> 
> (define (f x)
>    (let lp ((i 0) (s 0))
>        (if (< i (len x))
>            (lp (+ i 1) (+ (get x i) s))
>            s)))
> 
> Not an uncommon code. The problem is you should be able speed up the loop
> if len and get is generalized procedures by doing the dispatch once like
> this
> 
> (define (f x)
>    (let ((-len (find-dispatch len x))
>           (-get (find-dispatch get x)))
>      (let lp ((i 0) (s 0))
>          (if (< i (-len x))
>              (lp (+ i 1) (+ (-get x i) s))
>               s))))
> 
> The question is if we have such an interface or similar or if we should
> request that we get such a feature from the guile overlords.
> 
> Regards
> Stefan
>



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-10-10 20:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-10 15:16 goops speedups Stefan Israelsson Tampe
2020-10-10 20:12 ` Linus Björnstam

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).