<p>First a disclaimer: I am far from an expert on the subject, I'm just a regular Joe who happens to use OpenSCAD and have done some experimentation with it.  I believe the answer below to be correct, but I will be very grateful if errors or misconceptions were brought to my attention in the comments. :)</p>

<blockquote>
  <p>I have read that sometimes the function render is useful to speed up overall rendering.  Is this correct, or have I misunderstood?</p>
</blockquote>

<p>I'm unaware if it is possible to use <code>render()</code> to speed up the "overall rendering", but <strong>I'm rather confident that the <em>intended purpose</em> of <code>render()</code> is to simplify the in-memory representation of the model and thus the responsiveness of the preview window</strong>, rather than speed-up its final rendering.</p>

<blockquote>
  <p>How does this work?</p>
</blockquote>

<p>In order to understand how this work, one has to understand how Constructive Solid Geometry (CSG) works.</p>

<p>The entire premise of CSG is that using boolean operations between primitive solid shapes, it is possible to represent complex shapes.</p>

<p>However, while the human operator may see <em>subtractive</em> operations like difference and intersection as something that makes the model smaller in volume and thus possibly easier to handle, the computer sees each and every operation as <em>adding</em> geometry and complexity to the part, as the following image aptly illustrates:</p>

<p><a href="https://i.sstatic.net/TaMVb.png" rel="noreferrer"><img src="https://i.sstatic.net/TaMVb.png" alt="visuals vs in-memory model"></a></p>

<p>When manipulating the model in the CAD viewer, OpenSCAD is in the <em>preview mode</em> and all that "invisible geometry" needs to be processed for each adjustment of the viewport. It is easy to reach a level at which the OpenSCAD viewer will become jittery or unresponsive.</p>

<p><strong>What the <code>render()</code> function does, is telling OpenSCAD to compute the mesh resulting from the boolean operations enclosed in the <code>render()</code> call, and use that single mesh instead of the underlying boolean-combined primitives when handling the model in the viewer.</strong>  Meshes are what is normally used in the <em>render mode</em> of OpenSCAD (F6) rather than in the preview one, but here their advantage is not better visual quality, but the fact that OpenSCAD needs to handle a lot less geometry.</p>

<blockquote>
  <p>In what circumstances can I apply it?</p>
</blockquote>

<p><strong>You can apply it any time you like, really, but it is a trade-off</strong>: a model that uses the <code>render()</code> function internally, will take longer to display its initial preview (because generating the mesh is an expensive operation) but it will behave very well in the viewer.  Conversely, a large model that does not leverage <code>render()</code> will be jittery to handle in the viewer, but it will render to screen in a fraction of the time.  It has to be noted that OpenSCAD make heavy use of caching, so the first preview is the one that will take the longest, while successive ones may be a lot faster.</p>

<p><a href="https://i.sstatic.net/pxCyK.png" rel="noreferrer"><img src="https://i.sstatic.net/pxCyK.png" alt="small test"></a></p>

<p>For reference, the code at the bottom of this answer (which generates the image above) behaved like this:</p>

<ul>
<li>With <code>render()</code>: 15s for the preview, 1m29s more for the proper rendering (<strong>TOTAL: 1m44s</strong>).</li>
<li>Without <code>render()</code>: 0s for the preview, 1m45s more for the proper rendering (<strong>TOTAL: 1m45s</strong>).</li>
</ul>

<p><strong>I don't know if the fact that the totals resemble each other is a coincidence peculiar to my model or a general rule of thumb</strong> (the <code>render()</code> function effectively creating part of the final rendering during preview), but you are free to play with the code and if you find out a pattern, please leave a comment.</p>

<p>In the following code, you may need to increase the grid size to 20x20 if you want to see the difference in responsiveness between vanilla code and <code>render()</code> function.</p>

<p>Also remember to close and reopen OpenSCAD between tests, in order to flush the cache.</p>

<hr>

<pre><code>$fn = 30;

module shape() {
    render() difference() {
        sphere();
        cylinder(r=0.3, h=3, center=true);
        rotate([90, 0, 0]) cylinder(r=0.3, h=3, center=true);
        rotate([0, 90, 0]) cylinder(r=0.3, h=3, center=true);
        rotate([45, 0, 0]) cylinder(r=0.3, h=3, center=true);
        rotate([-45, 0, 0]) cylinder(r=0.3, h=3, center=true);
        rotate([0, 45, 0]) cylinder(r=0.3, h=3, center=true);
        rotate([0, -45, 0]) cylinder(r=0.3, h=3, center=true);
        rotate([90, 0, 45]) cylinder(r=0.3, h=3, center=true);
        rotate([90, 0, -45]) cylinder(r=0.3, h=3, center=true);
    }
}

module line(x, y) {
    translate([x * 2, y, 0]) shape();
    if (x &gt; 0) line(x - 1, y);
}    

module grid(x, y) {
    line(x, y * 2);
    if (y &gt; 0) grid(x, y - 1);
}

grid(3, 3);
</code></pre>

CC BY-SA 4.0
2023-09-24T15:20:39.607Z
Thanks for such a detailed write-up. Five years in the future, this helped me understand why my model is so jittery to navigate in preview and so smooth after rendering.
David L
CC BY-SA 3.0
2018-02-06T01:20:14.020Z
2018-02-06T01:20:14.020Z
mac
<p>To speed up the rendering, just change the rendering option to the new
Manifold: <strong>Edit &gt; Preferences &gt; Advanced &gt; 3D Rendering &gt; Backend &gt; Manifold (new/fast)</strong>. Then restart OpenScad to use the new rendering engine.</p>
<p><a href="https://i.sstatic.net/rU4tO0hk.png" rel="nofollow noreferrer" title="Screenshot of the OpenSCAD preferences showing the location of the option for faster 3D rendering"><img src="https://i.sstatic.net/rU4tO0hk.png" alt="Screenshot of the OpenSCAD preferences showing the location of the option for faster 3D rendering" title="Screenshot of the OpenSCAD preferences showing the location of the option for faster 3D rendering" /></a></p>
<p>This option has been available since <a href="https://fosstodon.org/@OpenSCAD/113256867413539398" rel="nofollow noreferrer">version 2024.09.28</a>.</p>
<p>Rendering time before: 0:00:21.824<br />
Rendering time after:  0:00:00.013</p>
<p>It's about 1678 times faster than the old one. I don't know why this is not the default option.</p>

CC BY-SA 4.0
2024-11-21T19:17:48.493Z
2024-11-22T14:42:58.357Z
2024-11-22T14:42:58.357Z
Tobse
<p>I am designing a moderately complicated piece in OpenScad.</p>

<p>It renders fast enough in preview mode (1s).
But when i do a full render so I can export to STL,
it takes ages (In the 10s of minutes)</p>

<p>I have read that sometimes the function <code>render</code> is useful to speed up overall rendering.</p>

<ul>
<li>Is this correct, or have I misunderstood?

<ul>
<li>If I have misunderstood, what is the <code>render</code> function useful for?</li>
</ul></li>
<li>How does this work?</li>
<li>In what circumstances can I apply it?</li>
</ul>

CC BY-SA 3.0
2018-02-05T13:46:49.700Z
What  processor chip is in your PC?  Why do you think those particular functions (union, difference) are the problem?  Is there a reason you can't finalize the booleans into a single object prior to rendering?
Carl Witthoft
CC BY-SA 3.0
2018-02-05T13:57:50.007Z
What does it mean to "finalize the booleans into a single object"? (I kinda thought render might be the command to do this, if it is what I think it is) 
PC Proc is  Core2 Duo E6750 2.66Ghz on one computer,
and i5-6400 2.70GHz on the other.


I think the bools are a problem because they are well known to be slow, they show up in almost every google result about rendering speed in every CAD program.
Frames Catherine White
CC BY-SA 3.0
2018-02-05T14:01:57.747Z
Though, to be fair, I gues Booleans probably show up in every nontirival openScad example, they are useful, I will tweak question
Frames Catherine White
CC BY-SA 3.0
2018-02-05T19:44:52.373Z
Fair enough - I was thinking in Meshmixer terms, where merging two objects can be done at any time, prior to a final cleanup or part rendering.
Carl Witthoft
CC BY-SA 3.0
2018-02-06T01:35:57.960Z
@CarlWitthoft - Boolean operations in CAD are *extremely* expensive, especially when the surfaces that need to be trimmed are curved.  In fact such operations are so complex that can't be solved in a sensible time, and for this reasons CAD packages use approximations that in turn makes most 3D models broken (and generate the occasional crash).  Google "Surface-to-surface intersection problem" if you want to learn more about this! :)
mac
<3d-design><cad><openscad>
Can the `render` function be used to speed up rendering?
Frames Catherine White
# Can the `render` function be used to speed up rendering?

(Asked by: username_0 on 2018-02-05)

I am designing a moderately complicated piece in OpenScad.

It renders fast enough in preview mode (1s).
But when i do a full render so I can export to STL,
it takes ages (In the 10s of minutes)

I have read that sometimes the function `render` is useful to speed up overall rendering.

* Is this correct, or have I misunderstood?
  + If I have misunderstood, what is the `render` function useful for?
* How does this work?
* In what circumstances can I apply it?

**Tags:** 3d-design, cad, openscad

> **Comments:**
> **username_1**: What  processor chip is in your PC?  Why do you think those particular functions (union, difference) are the problem?  Is there a reason you can't finalize the booleans into a single object prior to rendering?  
> **username_0**: What does it mean to "finalize the booleans into a single object"? (I kinda thought render might be the command to do this, if it is what I think it is)  PC Proc is  Core2 Duo E6750 2.66Ghz on one computer, and i5-6400 2.70GHz on the other.   I think the bools are a problem because they are well known to be slow, they show up in almost every google result about rendering speed in every CAD program.  
> **username_0**: Though, to be fair, I gues Booleans probably show up in every nontirival openScad example, they are useful, I will tweak question  
> **username_1**: Fair enough - I was thinking in Meshmixer terms, where merging two objects can be done at any time, prior to a final cleanup or part rendering.  
> **username_2**: @username_1 - Boolean operations in CAD are *extremely* expensive, especially when the surfaces that need to be trimmed are curved.  In fact such operations are so complex that can't be solved in a sensible time, and for this reasons CAD packages use approximations that in turn makes most 3D models broken (and generate the occasional crash).  Google "Surface-to-surface intersection problem" if you want to learn more about this! :)  

---

## 2 answers

### Answer by username_2 on 2018-02-06. Score: 10

First a disclaimer: I am far from an expert on the subject, I'm just a regular Joe who happens to use OpenSCAD and have done some experimentation with it. I believe the answer below to be correct, but I will be very grateful if errors or misconceptions were brought to my attention in the comments. :)

> I have read that sometimes the function render is useful to speed up overall rendering. Is this correct, or have I misunderstood?

I'm unaware if it is possible to use `render()` to speed up the "overall rendering", but **I'm rather confident that the *intended purpose* of `render()` is to simplify the in-memory representation of the model and thus the responsiveness of the preview window**, rather than speed-up its final rendering.

> How does this work?

In order to understand how this work, one has to understand how Constructive Solid Geometry (CSG) works.

The entire premise of CSG is that using boolean operations between primitive solid shapes, it is possible to represent complex shapes.

However, while the human operator may see *subtractive* operations like difference and intersection as something that makes the model smaller in volume and thus possibly easier to handle, the computer sees each and every operation as *adding* geometry and complexity to the part, as the following image aptly illustrates:

[![visuals vs in-memory model](https://i.sstatic.net/TaMVb.png)](https://i.sstatic.net/TaMVb.png)

When manipulating the model in the CAD viewer, OpenSCAD is in the *preview mode* and all that "invisible geometry" needs to be processed for each adjustment of the viewport. It is easy to reach a level at which the OpenSCAD viewer will become jittery or unresponsive.

**What the `render()` function does, is telling OpenSCAD to compute the mesh resulting from the boolean operations enclosed in the `render()` call, and use that single mesh instead of the underlying boolean-combined primitives when handling the model in the viewer.** Meshes are what is normally used in the *render mode* of OpenSCAD (F6) rather than in the preview one, but here their advantage is not better visual quality, but the fact that OpenSCAD needs to handle a lot less geometry.

> In what circumstances can I apply it?

**You can apply it any time you like, really, but it is a trade-off**: a model that uses the `render()` function internally, will take longer to display its initial preview (because generating the mesh is an expensive operation) but it will behave very well in the viewer. Conversely, a large model that does not leverage `render()` will be jittery to handle in the viewer, but it will render to screen in a fraction of the time. It has to be noted that OpenSCAD make heavy use of caching, so the first preview is the one that will take the longest, while successive ones may be a lot faster.

[![small test](https://i.sstatic.net/pxCyK.png)](https://i.sstatic.net/pxCyK.png)

For reference, the code at the bottom of this answer (which generates the image above) behaved like this:

* With `render()`: 15s for the preview, 1m29s more for the proper rendering (**TOTAL: 1m44s**).
* Without `render()`: 0s for the preview, 1m45s more for the proper rendering (**TOTAL: 1m45s**).

**I don't know if the fact that the totals resemble each other is a coincidence peculiar to my model or a general rule of thumb** (the `render()` function effectively creating part of the final rendering during preview), but you are free to play with the code and if you find out a pattern, please leave a comment.

In the following code, you may need to increase the grid size to 20x20 if you want to see the difference in responsiveness between vanilla code and `render()` function.

Also remember to close and reopen OpenSCAD between tests, in order to flush the cache.

---

```
$fn = 30;

module shape() {
    render() difference() {
        sphere();
        cylinder(r=0.3, h=3, center=true);
        rotate([90, 0, 0]) cylinder(r=0.3, h=3, center=true);
        rotate([0, 90, 0]) cylinder(r=0.3, h=3, center=true);
        rotate([45, 0, 0]) cylinder(r=0.3, h=3, center=true);
        rotate([-45, 0, 0]) cylinder(r=0.3, h=3, center=true);
        rotate([0, 45, 0]) cylinder(r=0.3, h=3, center=true);
        rotate([0, -45, 0]) cylinder(r=0.3, h=3, center=true);
        rotate([90, 0, 45]) cylinder(r=0.3, h=3, center=true);
        rotate([90, 0, -45]) cylinder(r=0.3, h=3, center=true);
    }
}

module line(x, y) {
    translate([x * 2, y, 0]) shape();
    if (x > 0) line(x - 1, y);
}    

module grid(x, y) {
    line(x, y * 2);
    if (y > 0) grid(x, y - 1);
}

grid(3, 3);

```

> **Comments:**
> **username_3**: Thanks for such a detailed write-up. Five years in the future, this helped me understand why my model is so jittery to navigate in preview and so smooth after rendering.  

---

### Answer by username_4 on 2024-11-21. Score: 2

To speed up the rendering, just change the rendering option to the new
Manifold: **Edit > Preferences > Advanced > 3D Rendering > Backend > Manifold (new/fast)**. Then restart OpenScad to use the new rendering engine.

[![Screenshot of the OpenSCAD preferences showing the location of the option for faster 3D rendering](https://i.sstatic.net/rU4tO0hk.png "Screenshot of the OpenSCAD preferences showing the location of the option for faster 3D rendering")](https://i.sstatic.net/rU4tO0hk.png "Screenshot of the OpenSCAD preferences showing the location of the option for faster 3D rendering")

This option has been available since [version 2024.09.28](https://fosstodon.org/@OpenSCAD/113256867413539398).

Rendering time before: 0:00:21.824  
Rendering time after:  0:00:00.013

It's about 1678 times faster than the old one. I don't know why this is not the default option.


---

