Shen-Language / shen-cl

Shen for Common Lisp (Unmaintained)
BSD 3-Clause "New" or "Revised" License
122 stars 11 forks source link

Native overrides #46

Closed tizoc closed 5 years ago

tizoc commented 5 years ago

Some overrides that worked well in Shen/Scheme

File reading overrides read the file into a pre-allocated buffer in one pass instead of byte by byte.

The tuple and vector constructors are overriden based on https://github.com/tizoc/shen-scheme/issues/9

Results for those same tests (but the amount of runs cut in 10):

name overrides no overrides 2.7.0 2.5.0
vec-read 1.0780 1.0800 1.0449 1.2870
vec-read+build@v 5.1330 12.0230 6.5480 7.7049
vec-read+build 2.8600 6.7909 3.9850 4.5209
list-hd 0.7720 0.8120 0.7730 1.1529
list-hd+cons 1.0220 1.0720 1.0260 1.2529
tuple-fst+build 1.9019 5.4489 3.3200 3.1049
control 0.7730 0.7729 0.7720 0.9850
total 13.5720 28.0379 17.5180 20.0480

For some reason, v3.0.0 without overrides is slower than both 2.7.0 and 2.5.0 in some cases, which means that in the transition to the new compiler I made some things worse, I have to investigate that. But overall, overriding those constructors improves performance like it did in Shen/Scheme.

code:

(package null []
 (define r
   V 100000000 -> ok
   V N -> (r V (+ N (<-address V 1))))

 (define rb1
   V 100000000 -> ok
   V N -> (rb1 (@v 1 <>)
               (+ N (<-address V 1))))

 (define rb2
   V 100000000 -> ok
   V N -> (rb2 (address-> (vector 1) 1 1)
               (+ N (<-address V 1))))

 (define c
   C 100000000 -> ok
   C N -> (c C (+ N (hd C))))

 (define c/b
   C 100000000 -> ok
   C N -> (c/b [1] (+ N (hd C))))

 (define t/b
   C 100000000 -> ok
   C N -> (t/b (@p 1 []) (+ N (fst C))))

 (define control
   C 100000000 -> ok
   C N -> (control C (+ N 1))))

(define collect-garbage
  -> (lisp. "(SB-EXT:GC)"))

(do (collect-garbage) (time (r (@v 1 <>) 1)))
(do (collect-garbage) (time (rb1 (@v 1 <>) 1)))
(do (collect-garbage) (time (rb2 (@v 1 <>) 1)))
(do (collect-garbage) (time (c  [1] 1)))
(do (collect-garbage) (time (c/b  [1] 1)))
(do (collect-garbage) (time (t/b (@p 1 []) 1)))
(do (collect-garbage) (time (control unit 1)))
rkoeninger commented 5 years ago

We could make notes on what things we tend to override in the benchmarks issue https://github.com/Shen-Language/shen-sources/issues/91

tizoc commented 5 years ago

For some reason, v3.0.0 without overrides is slower than both 2.7.0 and 2.5.0 in some cases, which means that in the transition to the new compiler I made some things worse, I have to investigate that

Weird, the code being generated in 3.0.0 vs 2.7.0 looks exactly the same to me (sans bar-quoting), but I keep getting the same higher times for 3.0.0 without overrides.