POV-Ray : Newsgroups : povray.general : Function performance : Re: Function performance Server Time
29 Jul 2024 12:29:38 EDT (-0400)
  Re: Function performance  
From: Thorsten Froehlich
Date: 23 Jul 2011 02:12:58
Message: <4e2a666a$1@news.povray.org>
On 22.07.11 23:51, David Given wrote:
> On 22/07/11 22:25, Thorsten Froehlich wrote:
> [...]
>> Well, as said, without the SDL I can't help as that is what in the end
>> determines how your functions are evaluated.
>
> I'm not looking to optimise this specific bit of code. I'm looking for
> general strategies in how to optimise code in general.
>
> For example: I assume that Povray parses functions into an AST, and then
> evaluates them by traversing the tree. Once the AST has been
> constructed, does it run any of the standard compiler optimisation
> algorithms on this such as common subexpression elimination or constant
> propagation?

Constant folding will always happen, as long as they are next to each other 
in the tree. This includes single-argument intrinsic functions. (sqrt, sin, 
cos, tan, abs, etc.). Further, there is inline expansion for pow, min and max.

There are no higher-level optimisations, as there is no detection (nor a 
complete list) of side effects some pattern functions do have (weel, had 
before 3.7). Further, the syntax tree is only kept as long as needed, which 
means as soon as the parser is done with a function.

Without knowing the specifics, most likely for your use the best way to 
eliminate common subexpressions is to use multiple functions and pass the 
subexpressions as arguments.

	Thorsten


Post a reply to this message

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