Version française
Home     About     Download     Resources     Contact us    
Browse thread
Ray tracer language comparison
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jon Harrop <jon@f...>
Subject: Ray tracer language comparison

I've updated my language comparison with four implementations in Scheme and 
one in Lisp:

  http://www.ffconsultancy.com/free/ray_tracer/languages.html

In short, Stalin's run-time performance is excellent (36% faster than 
ocamlopt) but its compile times are poor (2,000x slower than ocamlopt!) and 
SBCL-compiled Lisp is 6x slower than ocamlopt. Both Scheme and Lisp are >2x 
as verbose as OCaml.

Juho Snellman posted an interesting Lisp variant that used a macro to factor 
out unboxing, greatly reducing the stress on the GC and improving Lisp's 
performance to that of OCaml. Applying the same optimisation to the OCaml 
implementations makes them much faster again but I have yet to factor this 
out into a camlp4 macro.

This raises two interesting questions:

1. Can a camlp4 macro be written to factor out this unboxing transformation:

  let v = center -| orig in
  let b = dot v dir in
  let disc = b *. b -. dot v v +. radius *. radius in

where "+|" denotes vector addition and "*|" denotes scalar*vector 
multiplication. Transformed to:

  let vx = center.x -. orig.x in
  let vy = center.y -. orig.y in
  let vz = center.z -. orig.z in
  let b = vx *. dir.x +. vy *. dir.y +. vz *. dir.z in
  let vv = vx *. vx +. vy *. vy +. vz *. vz in
  let disc = b *. b -. vv +. radius *. radius in

So the intermediate vectors are not allocated and collected.

2. Manually inlining the code gives a huge performance improvement but using 
-inline does not appear to give this improvement. I assume ocamlopt can 
inline this but will not remove the boxing and subsequent unboxing. Is that 
right?

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists