POV-Ray : Newsgroups : povray.beta-test : Cached Macros! : Re: Cached Macros! Server Time
20 Apr 2024 10:26:18 EDT (-0400)
  Re: Cached Macros!  
From: clipka
Date: 18 Jul 2016 05:48:43
Message: <578ca5fb$1@news.povray.org>
Am 18.07.2016 um 10:05 schrieb Thomas de Groot:
> On 15-7-2016 1:15, clipka wrote:
>> While I'm satisfied with the cross-file macro execution speed, I would
>> like additional feedback from you guys about execution speed of macros
>> declared in the same file. I see a slight increase there, too -- can you
>> confirm?
> 
> Slight? You are kidding! :-)

Actually no, I'm not.

> The speed increase is huge in fact compared to version 3.7.
> With the attached quick-and-dirty scene I get the following results
> using 1 million iterations:
> 
> +av151; macro inside scene parsing time: 1 minute 5 seconds (65.988
> seconds)
> +av151; macro outside scene parsing time: 1 minute 6 seconds (66.971
> seconds)
> 
> V 3.7; macro inside scene parsing time: stopped parsing manually after
> more than 10 minutes!

I was quite puzzled about your results, until I saw your test scene, and
found that the in-file macro you presumably tested actually calls
various other macros, which are declared in rand.inc. So what you are
actually measuring is the speed of macro invocations across file boundaries.

With the macros RRand, VRand_In_Box and VRand_In_Obj moved to the scene
itself and "rand.inc" no longer included, I actually see a noteworthy
_slowdown_ in parsing time on my machine: about 60 seconds, as opposed
to 45 seconds with 3.7.0.


The picture changes a bit when the scene file is large -- or, more
precisely, when the macro is declared far away from where it is invoked:
With approximately 64k worth of comments inserted between the macro
declaration and its invocation, the parse time increases to about 95
seconds with 3.7.0, while remaining at about 60 seconds with the new
version.

This is to be expected, since the parser uses buffered file access, with
a 64k buffer on Windows machines, so in 3.7.0 a macro invoked from near
its declaration may still be included in the buffer, in which case
parsing can proceed without actual file access, while a farther-away
macro will trigger a 64k read to fill the buffer with different content.
It's still a good deal faster than cross-file invocation, since there is
no need to re-open another file. As for why macro caching is slower than
3.7.0's "near invocation", that's because it also adds a bit of overhead
every time a macro is invoked from the cache.

I'd be interested to hear from the Linux jockeys how they are faring
with in-file macro invocation. I'd expect a similar picture as with
Windows, but the "sweet spot" may be around 0.5k worth of code between
macro declaration and invocation, since that's the size of the buffer on
Unix. Then again, Unix may provide additional buffers for file access --
there must be a reason why POV-Ray's own buffers where chosen that small
on the Linux platform.


One thing seriously worrying me, however, is that the version using
cached macros exhibits seriously worse parsing performance on the 2nd
and any subsequent runs, taking about 100 seconds instead of 60 seconds.
Not sure yet what's going on there.


Post a reply to this message

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