English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Question about optimization
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-11-02 (14:50)
From: Jon Harrop <jonathandeanharrop@g...>
Subject: Re: [Caml-list] Question about optimization
On Sunday 02 November 2008 02:52:49 Michał C wrote:
> Hi!
> I'm working on a physical based ray(path) tracer and the performance
> is one of my top priorities (just after the image quality).
> So I have a question about optimization: can You share some tips or
> maybe optimizing strategies to improve the speed of programs?
> here is my code: http://neos1.ovh.org/ray3.ml,

Now that I can profile it, the single biggest problem is obviously that seven 
of my cores are idle!

You have manually un-nested pattern matches which is not necessary. For 
example, this:

	| Leaf (prim, mat) ->
		match prim with
			| Triangle (tri) -> ray_triangle ro rd tri
			| Sphere (sph) -> ray_sphere ro rd sph

May be written:

  | Leaf (Triangle tri, mat) -> ray_triangle ro rd tri
  | Leaf (Sphere sph, mat) -> ray_sphere ro rd sph

The only obvious optimizations I can see are to use a faster random number 
generator and to inline the vector arithmetic by hand.

Dr Jon Harrop, Flying Frog Consultancy Ltd.