Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* Question about optimization
@ 2008-11-02  2:52 Michał C
  2008-11-02 12:23 ` [Caml-list] " Peng Zang
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Michał C @ 2008-11-02  2:52 UTC (permalink / raw)
  To: caml-list

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,

and here is how I compile it:
ocamlopt -inline 100 -unsafe -ffast-math str.cmxa -I +lablgl  
lablgl.cmxa lablglut.cmxa -o ray ray.ml

Maybe You can take a look, sure I don't expect You to look through it  
in some hardcore way, but You know, maybe there are some obvious  
mistakes or unnecessary boxing which will spot your eye.

Thanks in advance,
oh and if you possibly want to see the development or how the program  
works - http://neos1.wordpress.com

Regards


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

* Re: [Caml-list] Question about optimization
  2008-11-02  2:52 Question about optimization Michał C
@ 2008-11-02 12:23 ` Peng Zang
  2008-11-02 13:02 ` Jon Harrop
  2008-11-02 15:52 ` Jon Harrop
  2 siblings, 0 replies; 4+ messages in thread
From: Peng Zang @ 2008-11-02 12:23 UTC (permalink / raw)
  To: caml-list; +Cc: Michał C

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I have often found -inline 10 to be faster than -inline 100.  But YMMV,

Peng

On Saturday 01 November 2008 10:52:49 pm 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,
>
> and here is how I compile it:
> ocamlopt -inline 100 -unsafe -ffast-math str.cmxa -I +lablgl
> lablgl.cmxa lablglut.cmxa -o ray ray.ml
>
> Maybe You can take a look, sure I don't expect You to look through it
> in some hardcore way, but You know, maybe there are some obvious
> mistakes or unnecessary boxing which will spot your eye.
>
> Thanks in advance,
> oh and if you possibly want to see the development or how the program
> works - http://neos1.wordpress.com
>
> Regards
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.7 (GNU/Linux)

iD8DBQFJDZu5fIRcEFL/JewRAikYAJ4qaO/HbPoVVP9xl3bCoYc0A17vlwCfbFyJ
tkVitQkbANKQYhDxM2lfNQc=
=2ycS
-----END PGP SIGNATURE-----


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

* Re: [Caml-list] Question about optimization
  2008-11-02  2:52 Question about optimization Michał C
  2008-11-02 12:23 ` [Caml-list] " Peng Zang
@ 2008-11-02 13:02 ` Jon Harrop
  2008-11-02 15:52 ` Jon Harrop
  2 siblings, 0 replies; 4+ messages in thread
From: Jon Harrop @ 2008-11-02 13:02 UTC (permalink / raw)
  To: caml-list

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,
>
> and here is how I compile it:
> ocamlopt -inline 100 -unsafe -ffast-math str.cmxa -I +lablgl
> lablgl.cmxa lablglut.cmxa -o ray ray.ml

Looks good but get rid of -unsafe and use records to represent vectors instead 
of arrays and compile in 64-bit and get rid of -ffast-math.

I don't know if it affects performance but get rid of conditions returning 
bool constants:

  if hc2 < 0. then false else true

Should be:

  hc2 >= 0.

> Maybe You can take a look, sure I don't expect You to look through it
> in some hardcore way, but You know, maybe there are some obvious
> mistakes or unnecessary boxing which will spot your eye.
>
> Thanks in advance,
> oh and if you possibly want to see the development or how the program
> works - http://neos1.wordpress.com

May I have an example scene description file that I can use for profiling? 
Without it, I have no way to direct my effort...

-- 
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e


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

* Re: [Caml-list] Question about optimization
  2008-11-02  2:52 Question about optimization Michał C
  2008-11-02 12:23 ` [Caml-list] " Peng Zang
  2008-11-02 13:02 ` Jon Harrop
@ 2008-11-02 15:52 ` Jon Harrop
  2 siblings, 0 replies; 4+ messages in thread
From: Jon Harrop @ 2008-11-02 15:52 UTC (permalink / raw)
  To: caml-list

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.
http://www.ffconsultancy.com/?e


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

end of thread, other threads:[~2008-11-02 14:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-02  2:52 Question about optimization Michał C
2008-11-02 12:23 ` [Caml-list] " Peng Zang
2008-11-02 13:02 ` Jon Harrop
2008-11-02 15:52 ` Jon Harrop

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox