manuel-serrano / bigloo

a practical Scheme compiler
http://www-sop.inria.fr/indes/fp/Bigloo
Other
135 stars 19 forks source link

vector-for-each: simple function seems to be faster than the new builtin #26

Closed svenha closed 5 years ago

svenha commented 5 years ago

bigloo has a new builtin function vector-for-each (using a compiler expander). But a simple function seems to be faster:

(define (vector-for-each pred v)
  (do ((i 0 (+ i 1))
       (end (vector-length v)))
    ((>= i end))
    (pred (vector-ref v i))))

Of course, this solution is missing a dispatch for the two-vector case and the n-vector case.

manuel-serrano commented 5 years ago

Hi Sven,

This is not what I observe. Considering the following program:

(module foo (main main))

(define (main argv) (define v (make-vector 100000 10)) (define f (if (equal? (getenv "FAST") "fast") test2 test))

(print (if (equal? (getenv "FAST") "fast") "fast" "slow"))

(let loop ((i (if (pair? (cdr argv)) (string->integer (cadr argv)) 10000))) (when (>fx i 0) (f v) (loop (-fx i 1)))))

(define (vfor-each pred v) (do ((i 0 (+ i 1)) (end (vector-length v))) ((>= i end)) (pred (vector-ref v i))))

(define (test v) (define (pred x) (integer? x))

(vfor-each pred v))

(define (test2 v) (define (pred x) (integer? x)) (vector-for-each pred v))

The version using the buitin vector-for-each version is about 3 times faster (which is expected because the macro-expansion of vector-for-each enables the compiler to eliminate the indirect call to integer?). Don't you observe something similar?

svenha commented 5 years ago

For this example, I see a similar speedup of 2.1. Hence, there must be some other effect in my affected program. I will investigate further, but I close this issue.

svenha commented 5 years ago

@manuel-serrano, how about removing vector-for-each definitions from bglstone (maze.scm)? Then we can track the performance of vector-for-each with the help of bglstone.

manuel-serrano commented 5 years ago

Done. I will generate a new bgltone tarball.

svenha commented 5 years ago

Thanks for the new bglstone version; it works as expected.