discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Rendering With Debugging Symbols

NS
Nathan Sokalski
Fri, Mar 15, 2024 7:38 PM

I have a model that seems to be taking a long time to render (and sometimes preview), so I obviously need to figure out where the problem is, so I am using the debug symbols (* and !). However, even when I have everything other than a couple simple elements (for example, polygon with linear_extrude), it still takes a lot longer than it should. I am wondering if elements marked with the * are still "rendered in memory" just not included in the result, causing the long amount of rendering time. Do I need to actually comment out (using // instead of *) the elements to do my debugging? To put it simply, does OpenSCAD attempt to think about elements with * at all, or does it think about them and just not display them?

Nathan Sokalski
njsokalski@hotmail.commailto:njsokalski@hotmail.com

I have a model that seems to be taking a long time to render (and sometimes preview), so I obviously need to figure out where the problem is, so I am using the debug symbols (* and !). However, even when I have everything other than a couple simple elements (for example, polygon with linear_extrude), it still takes a lot longer than it should. I am wondering if elements marked with the * are still "rendered in memory" just not included in the result, causing the long amount of rendering time. Do I need to actually comment out (using // instead of *) the elements to do my debugging? To put it simply, does OpenSCAD attempt to think about elements with * at all, or does it think about them and just not display them? Nathan Sokalski njsokalski@hotmail.com<mailto:njsokalski@hotmail.com>
MK
Marius Kintel
Fri, Mar 15, 2024 9:48 PM

Yes, OpenSCAD will still evaluate all the code even if you use debugging symbols to isolate rendering.
Only the visible code needs to be actually rendered, but you could be running into performance issues related to language evaluation, not rendering.

It would be easier to diagnose if you could share an example.

-Marius

On Mar 15, 2024, at 15:38, Nathan Sokalski via Discuss discuss@lists.openscad.org wrote:

I have a model that seems to be taking a long time to render (and sometimes preview), so I obviously need to figure out where the problem is, so I am using the debug symbols (* and !). However, even when I have everything other than a couple simple elements (for example, polygon with linear_extrude), it still takes a lot longer than it should. I am wondering if elements marked with the * are still "rendered in memory" just not included in the result, causing the long amount of rendering time. Do I need to actually comment out (using // instead of *) the elements to do my debugging? To put it simply, does OpenSCAD attempt to think about elements with * at all, or does it think about them and just not display them?

Nathan Sokalski
njsokalski@hotmail.com mailto:njsokalski@hotmail.com


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org mailto:discuss-leave@lists.openscad.org

Yes, OpenSCAD will still evaluate all the code even if you use debugging symbols to isolate rendering. Only the visible code needs to be actually rendered, but you could be running into performance issues related to language evaluation, not rendering. It would be easier to diagnose if you could share an example. -Marius > On Mar 15, 2024, at 15:38, Nathan Sokalski via Discuss <discuss@lists.openscad.org> wrote: > > I have a model that seems to be taking a long time to render (and sometimes preview), so I obviously need to figure out where the problem is, so I am using the debug symbols (* and !). However, even when I have everything other than a couple simple elements (for example, polygon with linear_extrude), it still takes a lot longer than it should. I am wondering if elements marked with the * are still "rendered in memory" just not included in the result, causing the long amount of rendering time. Do I need to actually comment out (using // instead of *) the elements to do my debugging? To put it simply, does OpenSCAD attempt to think about elements with * at all, or does it think about them and just not display them? > > Nathan Sokalski > njsokalski@hotmail.com <mailto:njsokalski@hotmail.com> > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org <mailto:discuss-leave@lists.openscad.org>
JB
Jordan Brown
Fri, Mar 15, 2024 9:58 PM

On 3/15/2024 12:38 PM, Nathan Sokalski via Discuss wrote:

I have a model that seems to be taking a long time to render (and
sometimes preview), so I obviously need to figure out where the
problem is, so I am using the debug symbols (* and !). However, even
when I have everything other than a couple simple elements (for
example, polygon with linear_extrude), it still takes a lot longer
than it should. I am wondering if elements marked with the * are still
"rendered in memory" just not included in the result, causing the long
amount of rendering time. Do I need to actually comment out (using //
instead of *) the elements to do my debugging? To put it simply, does
OpenSCAD attempt to think about elements with * at all, or does it
think about them and just not display them?

First let's get some terminology straight.  Not that I would claim that
anybody else uses this particular terminology, but I'd say that there
are approximately four phases in the execution of an OpenSCAD program:

  • Parsing.  Examines the program and turns it into an "abstract syntax
    tree".
  • Execution.  Walks the AST, assigning values, looping, et cetera, and
    generating a Constructive Solid Geometry tree.

then either

  • Preview (F5).  Walks the CSG tree, does black magic, and quickly
    displays the model from the current view angle.  Note that this step
    gets run any time you move the camera.
  • Render (F6).  Walks the CSG tree and laboriously calculates the
    resulting mesh.

For most models, the only part of that that takes a long time is the
"render" step.  That step is much faster with Manifold than it is with CGAL.

For some models, the "execution" step can take a long time.  As a data
point, "for (i=[0:1000], j=[0:1000], k=[0:10]);", a
ten-million-iteration loop, takes about 3 seconds on my system.

So the question is when the debug modifiers are processed.

The debug modifiers do not block parsing.  (Comments, of course, do.) 
If you have a syntax error, you have a syntax error.

The * modifier blocks execution.  If I put a * in front of that "for"
loop, the execution time goes away.  Notably, "*echo(whatever);" will
not be executed.

To my surprise, the % modifier blocks its subtree from being part of the
model, but mostly does not block it from being processed during the
"render" phase.  My test program (500 partially overlapping cubes, plus
a sphere) takes 6s to render, but 5s to render with a % in front of the
for loop, only a ~15% reduction.

The # modifier doesn't block anything.

The ! modifier blocks rendering of other elements, but does not block
execution of those elements.  Notably, echo() calls are executed.

Here's my test program.  Mark lines with modifiers and/or comment out to
construct test cases.  Note that I was using CGAL; if you have Manifold
enabled you probably need more cubes to get to a run time that you can
reasonably measure and compare.  (5000 got me a 2s render time.)

echo("hello");
for (i=[1:1000], j=[1:1000], k=[1:10]);
for (i=[1:500]) translate([i,i,i]) cube(10);
sphere(20);
On 3/15/2024 12:38 PM, Nathan Sokalski via Discuss wrote: > I have a model that seems to be taking a long time to render (and > sometimes preview), so I obviously need to figure out where the > problem is, so I am using the debug symbols (* and !). However, even > when I have everything other than a couple simple elements (for > example, polygon with linear_extrude), it still takes a lot longer > than it should. I am wondering if elements marked with the * are still > "rendered in memory" just not included in the result, causing the long > amount of rendering time. Do I need to actually comment out (using // > instead of *) the elements to do my debugging? To put it simply, does > OpenSCAD attempt to think about elements with * at all, or does it > think about them and just not display them? First let's get some terminology straight.  Not that I would claim that anybody else uses this particular terminology, but I'd say that there are approximately four phases in the execution of an OpenSCAD program: * Parsing.  Examines the program and turns it into an "abstract syntax tree". * Execution.  Walks the AST, assigning values, looping, et cetera, and generating a Constructive Solid Geometry tree. then either * Preview (F5).  Walks the CSG tree, does black magic, and quickly displays the model from the current view angle.  Note that this step gets run any time you move the camera. * Render (F6).  Walks the CSG tree and laboriously calculates the resulting mesh. For most models, the only part of that that takes a long time is the "render" step.  That step is much faster with Manifold than it is with CGAL. For some models, the "execution" step can take a long time.  As a data point, "for (i=[0:1000], j=[0:1000], k=[0:10]);", a ten-million-iteration loop, takes about 3 seconds on my system. So the question is when the debug modifiers are processed. The debug modifiers do not block parsing.  (Comments, of course, do.)  If you have a syntax error, you have a syntax error. The * modifier blocks execution.  If I put a * in front of that "for" loop, the execution time goes away.  Notably, "*echo(whatever);" will not be executed. To my surprise, the % modifier blocks its subtree from being part of the model, but mostly does *not* block it from being processed during the "render" phase.  My test program (500 partially overlapping cubes, plus a sphere) takes 6s to render, but 5s to render with a % in front of the for loop, only a ~15% reduction. The # modifier doesn't block anything. The ! modifier blocks rendering of other elements, but does not block execution of those elements.  Notably, echo() calls are executed. Here's my test program.  Mark lines with modifiers and/or comment out to construct test cases.  Note that I was using CGAL; if you have Manifold enabled you probably need more cubes to get to a run time that you can reasonably measure and compare.  (5000 got me a 2s render time.) echo("hello"); for (i=[1:1000], j=[1:1000], k=[1:10]); for (i=[1:500]) translate([i,i,i]) cube(10); sphere(20);