From: Jon Harrop <jon@ffconsultancy.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Announce: glome-0.2 (ocaml-based raytracer)
Date: Fri, 12 Jan 2007 12:16:40 +0000 [thread overview]
Message-ID: <200701121216.40859.jon@ffconsultancy.com> (raw)
In-Reply-To: <45A6E34A.6040007@cs.pdx.edu>
On Friday 12 January 2007 01:24, Jim Snow wrote:
> I've been working on a raytracer for awhile, and recently decided to
> remove a lot of experimental code that doesn't work well anyways and
> release the rest under the gpl version 2. Currently, glome renders some
> of the scenes from the standard procedural database
> (http://www.acm.org/tog/resources/SPD/). I thought that, aside from the
> practical utility of generating pretty pictures, some people on this
> list might be interested in using it to benchmark the quality of code
> generated by various versions of the ocaml compiler.
I have altered the code to be more idiomatic OCaml, although it is still very
not-OCaml. I've removed OOP from the hot path and virtual function dispatch
has been replaced with pattern matches.
http://www.ffconsultancy.com/temp/glome.tar.bz2
The code is now 1390LOC instead of 1746 (20% shorter). Performance is also
better. Building the Kd-tree is down from 7.0s to 6.3s.
I have many suggestions for what to do next:
1. Use records instead of float arrays: stronger type inference, more concise,
purely functional.
2. Get rid of almost all mutation. The core ray tracer has no reason to use
mutation and all those refs and assignments are confusing and probably slow.
3. Restructure the program again: put independent definitions related to
triangles in Triangle, put related definitions like the intersection routine
in Intersect.
Primarily, the program is far too verbose and convoluted. As an algorithm, ray
tracing is very functional in nature. I think the functionality provided by
this program could be achieved in half as many lines of code. It could also
be a lot faster.
> Supported primitives are spheres and triangles. It uses a kd-tree as an
> acceleration structure. There is limited joystick support (moving works
> fine, but turning can have unexpected results) for those patient enough
> to tolerate the low framerates.
>
> I use lablgl for screen output, but there aren't any other libraries
> required outside of the standard ocaml distribution.
Rather than rendering dots, you could generate a polygon mesh. To make things
more interesting, you could include the depth value in the mesh, so when you
rotate the scene it gets distorted by OpenGL without needing to ray trace
anything.
> I'm not a very experienced ocaml programmer, so I'm sure there are some
> things I'm doing inefficiently just because I don't know better. I
> welcome any suggestions that would make my code faster, or reduce the
> memory footprint of my scene representation.
My impression is that you are optimising prematurely. Get the program <1/2 the
size that it is before you even think about optimising anything. You're doing
all sorts of manual resource allocation and mutation thinking that it will
make things faster when, I think, it just makes the program unnecessarily
complicated.
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists
next prev parent reply other threads:[~2007-01-12 12:18 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-01-12 1:24 Jim Snow
2007-01-12 12:16 ` Jon Harrop [this message]
2007-01-15 10:30 ` [Caml-list] " Jim Snow
2007-01-15 18:34 ` brogoff
2007-01-17 23:01 ` Nathaniel Gray
2007-01-17 23:09 ` Jon Harrop
[not found] ` <200701151206.34251.jon@ffconsultancy.com>
[not found] ` <45ABFB4D.3000605@cs.pdx.edu>
[not found] ` <200701152259.10598.jon@ffconsultancy.com>
2007-01-18 10:29 ` Jim Snow
2007-01-18 14:01 ` Jon Harrop
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200701121216.40859.jon@ffconsultancy.com \
--to=jon@ffconsultancy.com \
--cc=caml-list@yquem.inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox