discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Module caching

NH
nop head
Tue, Jan 22, 2019 11:10 PM

I was under the impression that if a module was instantiated multiple times
with the same parameters the results were cached and reused.

If I make a module that renders() the difference between a cube and a
sphere with lots of vertices  and use it 100 times in a preview it take the
same time to preview 100 as it does one. I.e. it only does the slow
difference once and then draws the result 100 times.

However if I generate a spring using a helical sweep of a circle than it
takes about 1 second to preview one and 100 seconds to preview 100.

So it seems I misunderstood the caching. It only seems to cache CGAL
operations, not the actual instantiation of the module. It still needs to
calculate the sweep each time despite all the springs being identical. Is
this the case? I.e. it doesn't shortcut modules when the parameters don't
change?

I am surprised it takes a second to generate all the vertices for the
polyhedron. It is about 9000 facets generated with list comprehensions and
transformations in an interpreted language, but even so, PCs are very fast.

[image: image.png]

Looks like I need to save the points and face lists myself and reuse them.

I was under the impression that if a module was instantiated multiple times with the same parameters the results were cached and reused. If I make a module that renders() the difference between a cube and a sphere with lots of vertices and use it 100 times in a preview it take the same time to preview 100 as it does one. I.e. it only does the slow difference once and then draws the result 100 times. However if I generate a spring using a helical sweep of a circle than it takes about 1 second to preview one and 100 seconds to preview 100. So it seems I misunderstood the caching. It only seems to cache CGAL operations, not the actual instantiation of the module. It still needs to calculate the sweep each time despite all the springs being identical. Is this the case? I.e. it doesn't shortcut modules when the parameters don't change? I am surprised it takes a second to generate all the vertices for the polyhedron. It is about 9000 facets generated with list comprehensions and transformations in an interpreted language, but even so, PCs are very fast. [image: image.png] Looks like I need to save the points and face lists myself and reuse them.
P
Parkinbot
Tue, Jan 22, 2019 11:34 PM

polyhedrons don't get cached. The cache mechanism would have to hash both
parameters.

--
Sent from: http://forum.openscad.org/

polyhedrons don't get cached. The cache mechanism would have to hash both parameters. -- Sent from: http://forum.openscad.org/
NH
nop head
Sat, Jan 26, 2019 12:07 AM

So I rewrote my spring module as a function that returns a mesh (points and
faces) so I can save it as a variable and then re-use it to draw many
springs by simply calling polyhedron.

100 springs was taking 61 seconds when it was doing a sweep for each one.
With only one sweep to generate the mesh and 100 calls of polygon it now
takes 23 seconds. Why is polyhedron so slow? I expected it to by
instantaneous in F5. All it has to do is process the lists into a polyset.

On Tue, 22 Jan 2019 at 23:35, Parkinbot rudolf@digitaldocument.de wrote:

polyhedrons don't get cached. The cache mechanism would have to hash both
parameters.

--
Sent from: http://forum.openscad.org/


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

So I rewrote my spring module as a function that returns a mesh (points and faces) so I can save it as a variable and then re-use it to draw many springs by simply calling polyhedron. 100 springs was taking 61 seconds when it was doing a sweep for each one. With only one sweep to generate the mesh and 100 calls of polygon it now takes 23 seconds. Why is polyhedron so slow? I expected it to by instantaneous in F5. All it has to do is process the lists into a polyset. On Tue, 22 Jan 2019 at 23:35, Parkinbot <rudolf@digitaldocument.de> wrote: > polyhedrons don't get cached. The cache mechanism would have to hash both > parameters. > > > > -- > Sent from: http://forum.openscad.org/ > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
P
Parkinbot
Sat, Jan 26, 2019 1:06 PM

I guess I don't have to tell you you can "activate" the cache by importing an
STL of the spring as a work around.
Therefore I understand your question more like: Why isn't/can't polyhedron
be implemented to be faster.

Marius pointed out in a post some years ago that OpenSCAD has to sort out a
structure from the triag soup when importing a STL. So, even for F5 it
cannot just copy the soup into the GPU, but has to analyse it.
While a STL contains triags only, polyhedron can be called with arbitrary
polygon faces. This for sure will create additional overhead.

--
Sent from: http://forum.openscad.org/

I guess I don't have to tell you you can "activate" the cache by importing an STL of the spring as a work around. Therefore I understand your question more like: Why isn't/can't polyhedron be implemented to be faster. Marius pointed out in a post some years ago that OpenSCAD has to sort out a structure from the triag soup when importing a STL. So, even for F5 it cannot just copy the soup into the GPU, but has to analyse it. While a STL contains triags only, polyhedron can be called with arbitrary polygon faces. This for sure will create additional overhead. -- Sent from: http://forum.openscad.org/
NH
nop head
Sat, Jan 26, 2019 5:33 PM

But OpenSCAD's Polyset class is just a polygon soup, so no better than STL
and suffers all the same problems as far as I can see. You have to sort
anything out to make one from a polyhedron, just convert the face lists to
polygons by indexing the points. You are actually going from a more
structured data format to a less complicated one. I think it is only if you
want to use it with CGAL that a more complicated data structure is used,
I.e. Nef_Polyhedron. For an F5 preview a PolySet should be all you need. It
needs to be triangulated but I have already done that for all but the
endcaps.

The code is here:
https://github.com/openscad/openscad/blob/69bf5a55475102be43c2ddc698198e85821332b3/src/primitives.cc#L552
I don't see anything that would take any time on a modern PC that runs at
GHz.

On Sat, 26 Jan 2019 at 13:08, Parkinbot rudolf@digitaldocument.de wrote:

I guess I don't have to tell you you can "activate" the cache by importing
an
STL of the spring as a work around.
Therefore I understand your question more like: Why isn't/can't polyhedron
be implemented to be faster.

Marius pointed out in a post some years ago that OpenSCAD has to sort out a
structure from the triag soup when importing a STL. So, even for F5 it
cannot just copy the soup into the GPU, but has to analyse it.
While a STL contains triags only, polyhedron can be called with arbitrary
polygon faces. This for sure will create additional overhead.

--
Sent from: http://forum.openscad.org/


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

But OpenSCAD's Polyset class is just a polygon soup, so no better than STL and suffers all the same problems as far as I can see. You have to sort anything out to make one from a polyhedron, just convert the face lists to polygons by indexing the points. You are actually going from a more structured data format to a less complicated one. I think it is only if you want to use it with CGAL that a more complicated data structure is used, I.e. Nef_Polyhedron. For an F5 preview a PolySet should be all you need. It needs to be triangulated but I have already done that for all but the endcaps. The code is here: https://github.com/openscad/openscad/blob/69bf5a55475102be43c2ddc698198e85821332b3/src/primitives.cc#L552 I don't see anything that would take any time on a modern PC that runs at GHz. On Sat, 26 Jan 2019 at 13:08, Parkinbot <rudolf@digitaldocument.de> wrote: > I guess I don't have to tell you you can "activate" the cache by importing > an > STL of the spring as a work around. > Therefore I understand your question more like: Why isn't/can't polyhedron > be implemented to be faster. > > Marius pointed out in a post some years ago that OpenSCAD has to sort out a > structure from the triag soup when importing a STL. So, even for F5 it > cannot just copy the soup into the GPU, but has to analyse it. > While a STL contains triags only, polyhedron can be called with arbitrary > polygon faces. This for sure will create additional overhead. > > > > > -- > Sent from: http://forum.openscad.org/ > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
NH
nop head
Sat, Jan 26, 2019 7:11 PM

Is it perhaps that the lists are stored as strings when the polyhedron is
instantiated and then parsed to vectors every time the geometry is created.

Would converting them to vectors of doubles in PrimitiveModule::instantiate
make it faster or is that called 100 times as well?

On Sat, 26 Jan 2019 at 17:33, nop head nop.head@gmail.com wrote:

But OpenSCAD's Polyset class is just a polygon soup, so no better than STL
and suffers all the same problems as far as I can see. You have to sort
anything out to make one from a polyhedron, just convert the face lists to
polygons by indexing the points. You are actually going from a more
structured data format to a less complicated one. I think it is only if you
want to use it with CGAL that a more complicated data structure is used,
I.e. Nef_Polyhedron. For an F5 preview a PolySet should be all you need. It
needs to be triangulated but I have already done that for all but the
endcaps.

The code is here:
https://github.com/openscad/openscad/blob/69bf5a55475102be43c2ddc698198e85821332b3/src/primitives.cc#L552
I don't see anything that would take any time on a modern PC that runs at
GHz.

On Sat, 26 Jan 2019 at 13:08, Parkinbot rudolf@digitaldocument.de wrote:

I guess I don't have to tell you you can "activate" the cache by
importing an
STL of the spring as a work around.
Therefore I understand your question more like: Why isn't/can't polyhedron
be implemented to be faster.

Marius pointed out in a post some years ago that OpenSCAD has to sort out
a
structure from the triag soup when importing a STL. So, even for F5 it
cannot just copy the soup into the GPU, but has to analyse it.
While a STL contains triags only, polyhedron can be called with arbitrary
polygon faces. This for sure will create additional overhead.

--
Sent from: http://forum.openscad.org/


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

Is it perhaps that the lists are stored as strings when the polyhedron is instantiated and then parsed to vectors every time the geometry is created. Would converting them to vectors of doubles in PrimitiveModule::instantiate make it faster or is that called 100 times as well? On Sat, 26 Jan 2019 at 17:33, nop head <nop.head@gmail.com> wrote: > But OpenSCAD's Polyset class is just a polygon soup, so no better than STL > and suffers all the same problems as far as I can see. You have to sort > anything out to make one from a polyhedron, just convert the face lists to > polygons by indexing the points. You are actually going from a more > structured data format to a less complicated one. I think it is only if you > want to use it with CGAL that a more complicated data structure is used, > I.e. Nef_Polyhedron. For an F5 preview a PolySet should be all you need. It > needs to be triangulated but I have already done that for all but the > endcaps. > > The code is here: > https://github.com/openscad/openscad/blob/69bf5a55475102be43c2ddc698198e85821332b3/src/primitives.cc#L552 > I don't see anything that would take any time on a modern PC that runs at > GHz. > > On Sat, 26 Jan 2019 at 13:08, Parkinbot <rudolf@digitaldocument.de> wrote: > >> I guess I don't have to tell you you can "activate" the cache by >> importing an >> STL of the spring as a work around. >> Therefore I understand your question more like: Why isn't/can't polyhedron >> be implemented to be faster. >> >> Marius pointed out in a post some years ago that OpenSCAD has to sort out >> a >> structure from the triag soup when importing a STL. So, even for F5 it >> cannot just copy the soup into the GPU, but has to analyse it. >> While a STL contains triags only, polyhedron can be called with arbitrary >> polygon faces. This for sure will create additional overhead. >> >> >> >> >> -- >> Sent from: http://forum.openscad.org/ >> >> _______________________________________________ >> OpenSCAD mailing list >> Discuss@lists.openscad.org >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> >
P
Parkinbot
Sun, Jan 27, 2019 10:31 PM

nophead wrote

Is it perhaps that the lists are stored as strings when the polyhedron is
instantiated and then parsed to vectors every time the geometry is
created.

I doubt that. But you are right, the code really looks like nothing very
time consuming is happening.
Is the triangulation of the faces done by Open GL? What happens after the
geometry has been created?

--
Sent from: http://forum.openscad.org/

nophead wrote > Is it perhaps that the lists are stored as strings when the polyhedron is > instantiated and then parsed to vectors every time the geometry is > created. I doubt that. But you are right, the code really looks like nothing very time consuming is happening. Is the triangulation of the faces done by Open GL? What happens after the geometry has been created? -- Sent from: http://forum.openscad.org/
NH
nop head
Sun, Jan 27, 2019 10:58 PM

It spends most of the 22 seconds stuck at Compiling design (CSG Tree
generation)...

After that it does all the rest in about 1 second, including a very fast
progress bar.

Compiling design (CSG Products generation)...

Geometries in cache: 395

Geometry cache size in bytes: 20331104

CGAL Polyhedrons in cache: 0

CGAL cache size in bytes: 0

Compiling design (CSG Products normalization)...

Normalized CSG tree has 100 elements

Compile and preview finished.

Total rendering time: 0 hours, 0 minutes, 22 seconds

It would be a problem if I was designing a mattress with PLA springs but
fortunately only a battery box with four, but it would be nice if
polyhedrons were cached like other geometry seems to be. I clearly don't
fully understand OpenSCADs caching system.

On Sun, 27 Jan 2019 at 22:33, Parkinbot rudolf@digitaldocument.de wrote:

nophead wrote

Is it perhaps that the lists are stored as strings when the polyhedron is
instantiated and then parsed to vectors every time the geometry is
created.

I doubt that. But you are right, the code really looks like nothing very
time consuming is happening.
Is the triangulation of the faces done by Open GL? What happens after the
geometry has been created?

--
Sent from: http://forum.openscad.org/


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

It spends most of the 22 seconds stuck at Compiling design (CSG Tree generation)... After that it does all the rest in about 1 second, including a very fast progress bar. Compiling design (CSG Products generation)... Geometries in cache: 395 Geometry cache size in bytes: 20331104 CGAL Polyhedrons in cache: 0 CGAL cache size in bytes: 0 Compiling design (CSG Products normalization)... Normalized CSG tree has 100 elements Compile and preview finished. Total rendering time: 0 hours, 0 minutes, 22 seconds It would be a problem if I was designing a mattress with PLA springs but fortunately only a battery box with four, but it would be nice if polyhedrons were cached like other geometry seems to be. I clearly don't fully understand OpenSCADs caching system. On Sun, 27 Jan 2019 at 22:33, Parkinbot <rudolf@digitaldocument.de> wrote: > nophead wrote > > Is it perhaps that the lists are stored as strings when the polyhedron is > > instantiated and then parsed to vectors every time the geometry is > > created. > > I doubt that. But you are right, the code really looks like nothing very > time consuming is happening. > Is the triangulation of the faces done by Open GL? What happens after the > geometry has been created? > > > > -- > Sent from: http://forum.openscad.org/ > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
HL
Hans L
Mon, Jan 28, 2019 2:22 AM

Hi nophead,

Could you post a sample script for others to reproduce the slowness you
experience?

Thanks,
Hans

On Sun, Jan 27, 2019 at 4:59 PM nop head nop.head@gmail.com wrote:

It spends most of the 22 seconds stuck at Compiling design (CSG Tree
generation)...

After that it does all the rest in about 1 second, including a very fast
progress bar.

Compiling design (CSG Products generation)...

Geometries in cache: 395

Geometry cache size in bytes: 20331104

CGAL Polyhedrons in cache: 0

CGAL cache size in bytes: 0

Compiling design (CSG Products normalization)...

Normalized CSG tree has 100 elements

Compile and preview finished.

Total rendering time: 0 hours, 0 minutes, 22 seconds

It would be a problem if I was designing a mattress with PLA springs but
fortunately only a battery box with four, but it would be nice if
polyhedrons were cached like other geometry seems to be. I clearly don't
fully understand OpenSCADs caching system.

On Sun, 27 Jan 2019 at 22:33, Parkinbot rudolf@digitaldocument.de wrote:

nophead wrote

Is it perhaps that the lists are stored as strings when the polyhedron

is

instantiated and then parsed to vectors every time the geometry is
created.

I doubt that. But you are right, the code really looks like nothing very
time consuming is happening.
Is the triangulation of the faces done by Open GL? What happens after the
geometry has been created?

--
Sent from: http://forum.openscad.org/


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

Hi nophead, Could you post a sample script for others to reproduce the slowness you experience? Thanks, Hans On Sun, Jan 27, 2019 at 4:59 PM nop head <nop.head@gmail.com> wrote: > It spends most of the 22 seconds stuck at Compiling design (CSG Tree > generation)... > > After that it does all the rest in about 1 second, including a very fast > progress bar. > > Compiling design (CSG Products generation)... > > Geometries in cache: 395 > > Geometry cache size in bytes: 20331104 > > CGAL Polyhedrons in cache: 0 > > CGAL cache size in bytes: 0 > > Compiling design (CSG Products normalization)... > > Normalized CSG tree has 100 elements > > Compile and preview finished. > > Total rendering time: 0 hours, 0 minutes, 22 seconds > > > It would be a problem if I was designing a mattress with PLA springs but > fortunately only a battery box with four, but it would be nice if > polyhedrons were cached like other geometry seems to be. I clearly don't > fully understand OpenSCADs caching system. > > On Sun, 27 Jan 2019 at 22:33, Parkinbot <rudolf@digitaldocument.de> wrote: > >> nophead wrote >> > Is it perhaps that the lists are stored as strings when the polyhedron >> is >> > instantiated and then parsed to vectors every time the geometry is >> > created. >> >> I doubt that. But you are right, the code really looks like nothing very >> time consuming is happening. >> Is the triangulation of the faces done by Open GL? What happens after the >> geometry has been created? >> >> >> >> -- >> Sent from: http://forum.openscad.org/ >> >> _______________________________________________ >> OpenSCAD mailing list >> Discuss@lists.openscad.org >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
NH
nop head
Mon, Jan 28, 2019 8:58 AM

Here is a boiled down version:
https://gist.github.com/nophead/fd4ca58b5f6b19dc25bb98f7edbae90f

I captured the points and face lists generated by sweep and hard coded them
to remove all of my library. Each spring is 4576 points, 9122 faces but
they are all the same polyhedron repeated 100 times. Given that it doesn't
cache polyhedra it has to process the same lists to a Polyset 100 times.
Taking about 1/4 second to process 9000 faces seems very slow to me on a 64
bit 2.5GHz core I7 with 8 GB memory.

On Mon, 28 Jan 2019 at 02:23, Hans L thehans@gmail.com wrote:

Hi nophead,

Could you post a sample script for others to reproduce the slowness you
experience?

Thanks,
Hans

On Sun, Jan 27, 2019 at 4:59 PM nop head nop.head@gmail.com wrote:

It spends most of the 22 seconds stuck at Compiling design (CSG Tree
generation)...

After that it does all the rest in about 1 second, including a very fast
progress bar.

Compiling design (CSG Products generation)...

Geometries in cache: 395

Geometry cache size in bytes: 20331104

CGAL Polyhedrons in cache: 0

CGAL cache size in bytes: 0

Compiling design (CSG Products normalization)...

Normalized CSG tree has 100 elements

Compile and preview finished.

Total rendering time: 0 hours, 0 minutes, 22 seconds

It would be a problem if I was designing a mattress with PLA springs but
fortunately only a battery box with four, but it would be nice if
polyhedrons were cached like other geometry seems to be. I clearly don't
fully understand OpenSCADs caching system.

On Sun, 27 Jan 2019 at 22:33, Parkinbot rudolf@digitaldocument.de
wrote:

nophead wrote

Is it perhaps that the lists are stored as strings when the polyhedron

is

instantiated and then parsed to vectors every time the geometry is
created.

I doubt that. But you are right, the code really looks like nothing very
time consuming is happening.
Is the triangulation of the faces done by Open GL? What happens after the
geometry has been created?

--
Sent from: http://forum.openscad.org/


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

Here is a boiled down version: https://gist.github.com/nophead/fd4ca58b5f6b19dc25bb98f7edbae90f I captured the points and face lists generated by sweep and hard coded them to remove all of my library. Each spring is 4576 points, 9122 faces but they are all the same polyhedron repeated 100 times. Given that it doesn't cache polyhedra it has to process the same lists to a Polyset 100 times. Taking about 1/4 second to process 9000 faces seems very slow to me on a 64 bit 2.5GHz core I7 with 8 GB memory. On Mon, 28 Jan 2019 at 02:23, Hans L <thehans@gmail.com> wrote: > Hi nophead, > > Could you post a sample script for others to reproduce the slowness you > experience? > > Thanks, > Hans > > On Sun, Jan 27, 2019 at 4:59 PM nop head <nop.head@gmail.com> wrote: > >> It spends most of the 22 seconds stuck at Compiling design (CSG Tree >> generation)... >> >> After that it does all the rest in about 1 second, including a very fast >> progress bar. >> >> Compiling design (CSG Products generation)... >> >> Geometries in cache: 395 >> >> Geometry cache size in bytes: 20331104 >> >> CGAL Polyhedrons in cache: 0 >> >> CGAL cache size in bytes: 0 >> >> Compiling design (CSG Products normalization)... >> >> Normalized CSG tree has 100 elements >> >> Compile and preview finished. >> >> Total rendering time: 0 hours, 0 minutes, 22 seconds >> >> >> It would be a problem if I was designing a mattress with PLA springs but >> fortunately only a battery box with four, but it would be nice if >> polyhedrons were cached like other geometry seems to be. I clearly don't >> fully understand OpenSCADs caching system. >> >> On Sun, 27 Jan 2019 at 22:33, Parkinbot <rudolf@digitaldocument.de> >> wrote: >> >>> nophead wrote >>> > Is it perhaps that the lists are stored as strings when the polyhedron >>> is >>> > instantiated and then parsed to vectors every time the geometry is >>> > created. >>> >>> I doubt that. But you are right, the code really looks like nothing very >>> time consuming is happening. >>> Is the triangulation of the faces done by Open GL? What happens after the >>> geometry has been created? >>> >>> >>> >>> -- >>> Sent from: http://forum.openscad.org/ >>> >>> _______________________________________________ >>> OpenSCAD mailing list >>> Discuss@lists.openscad.org >>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >>> >> _______________________________________________ >> OpenSCAD mailing list >> Discuss@lists.openscad.org >> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >> > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >