POV-Ray : Newsgroups : povray.programming : Superpatch/MegaPOV function optimization : Re: Superpatch/MegaPOV function optimization Server Time
28 Jul 2024 16:15:07 EDT (-0400)
  Re: Superpatch/MegaPOV function optimization  
From: Nathan Kopp
Date: 21 Mar 2000 16:26:32
Message: <38d7e908$1@news.povray.org>
Lummox JR <Lum### [at] aolcom> wrote...
> Since the discussion of a raw noise function arose in povray.general,
> the
> topic of function optimization came up. I figure it's about time to
> start
> trying to hone that code past the point of theory, so I could use a lot
> of
> criticism.
>
> The basic technique here is to do a two-step process: 1.) Find all
> simple
> expressions or function calls that can be reduced to a constant. 2.)
> Find
> any expression that occurs more than once, and rewrite the function to
> look something like this:
>
> precalc(expression,rest of function)
>
> The precalc() function is internal, not open to the user. Its value is
> equal to the second argument, and the first argument's value can be used
> within the second by calling expr(). So precalc() acts as a sort of
> cache, calculating the bigger stuff first and reusing it later.
> Take this simple example:
>
> sqrt(sqr(x)+sqr(y)+sqr(z))-sqrt(sqr(x)+sqr(y)-sqr(z))
>
> Of that function, two expressions can be precalculated:
>
> sqr(x)+sqr(y)
> sqr(z)
>
> The result looks like this:
>
> precalc(sqr(z),precalc(sqr(x)+sqr(y),
>   sqrt(expr(1)+expr(0))-sqrt(expr(1)-expr(0))))
>
> It looks more complex, but it calculates faster.
>
> The following is the code I've developed to do all that. It hasn't been
> tested, and it's far from complete. Comments of any kind are welcome.

I like your ideas.  I haven't looked at your code, but the concept seems
solid.

-Nathan


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.