Google Groups Home
Help | Sign in
Message from discussion Optimise my ray tracer
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Lasse Reichstein Nielsen  
View profile
 More options 11 Jun 2005, 18:54
Newsgroups: comp.lang.java.programmer
From: Lasse Reichstein Nielsen <l...@hotpop.com>
Date: Sat, 11 Jun 2005 19:54:58 +0200
Local: Sat 11 Jun 2005 18:54
Subject: Re: Optimise my ray tracer

Jon Harrop <use...@jdh30.plus.com> writes:
> Lasse Reichstein Nielsen wrote:
>> Jon Harrop <use...@jdh30.plus.com> writes:
>>> I have taken startup time into consideration. Java is still consistently
>>> many times slower than most other languages.

>> Is this using the original code that was posted here? Because it can
>> be written significantly better.

> Great, tell me how (provided it doesn't get too much longer).

I posted a link to a slightly optimized version. I don't know if
I am changing the algorithm too much for comparison (e.g., moving
loop invariant code out of the loop) and doing all the I/O at the
end instead of during the computation.

<URL: http://www.infimum.dk/privat/RayTracing.java >
(I changed the class name too, to a more traditional Java format).

I admit to having performed "optimizations" without profiling first,
so there is no telling which change does what, but it does give
me an ~30% increase in speed for size=100.

> With the vector class declared static (what exactly does this do?)

It makes the class more independent of the surrounding class, so each
Vector doesn't have to carry around a reference to a "ray" object that
it never uses.

In a real program, I would put all the nested classes into their own
files.

> it takes 29s, which is not significantly faster.

My guess is that a lot of the time comes from I/O (ok, just O, it only
does output :).

> In contrast, Mlton-compiled SML is much shorter (79 vs 110 LOC) and runs
> about 5x as fast, taking only 6s to ray trace exactly the same image.

Brevity of code is not in itself a quality. Java is often more verbose
than other languages, but I also often find it more readable, because
differet programmers can't invent their own dialect.

> So we really need much better optimisations if Java is going to perform
> anything like as well as the other languages. Am I missing something
> simple, like JIT or optimisation flags?

Can't help you there. I rarely fiddle with flags :)

Btw, is the generated image correct? It looks odd.
/L
--
Lasse Reichstein Nielsen  -  l...@hotpop.com
 DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
  'Faith without judgement merely degrades the spirit divine.'


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google