discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

"use" results in 3x more run time than "include"

RD
Revar Desmera
Sun, Apr 14, 2019 2:11 AM

Aha!  Minimal code to reproduce:
use.scad:

function foo(x) = x;
x=echo("DANGER DANGER! DANGER, Will Robinson!");

main.scad:

use <use.scad>
y = foo(2);

Output:

Used file cache size: 2 files
Compiling design (CSG Tree generation)...
ECHO: "DANGER DANGER! DANGER, Will Robinson!"
Compiling design (CSG Products generation)...
Geometries in cache: 1
Geometry cache size in bytes: 728
CGAL Polyhedrons in cache: 0
CGAL cache size in bytes: 0
Compiling design (CSG Products normalization)...
Normalized CSG tree has 0 elements
Compile and preview finished.
Total rendering time: 0 hours, 0 minutes, 0 seconds
  • Revar

On Apr 13, 2019, at 7:03 PM, Revar Desmera revarbat@gmail.com wrote:

Well THIS is interesting.  I know I reproduced nop head's results with the version of OpenSCAD I'm running (2019-03-03) just a week or so ago.
But this code below does NOT reproduce it.

  • Revar

On Apr 13, 2019, at 5:59 PM, Jordan Brown <openscad@jordan.maileater.net mailto:openscad@jordan.maileater.net> wrote:

On 4/13/2019 5:37 PM, Revar Desmera wrote:

I suspect part of the delay isn't just search order, but that it's actually re-defining/recompiling the functions on each use.  The fact that echo()s at top-level are executed any time a function in a used library is called, makes me suspect the function declarations are also being re-executed.

With 2019.01-RC2 I don't see the behavior that you describe.

I have a main file
use <use.scad>

foo();
translate([10,10]) foo();
echo(f(0));
and use.scad is:
echo("top");

module foo() {
cube();
}

function f(n) = n+1;

echo("bottom");
and the only echo output is the expected "ECHO: 1".

Aha! Minimal code to reproduce: use.scad: ``` function foo(x) = x; x=echo("DANGER DANGER! DANGER, Will Robinson!"); ``` main.scad: ``` use <use.scad> y = foo(2); ``` Output: ``` Used file cache size: 2 files Compiling design (CSG Tree generation)... ECHO: "DANGER DANGER! DANGER, Will Robinson!" Compiling design (CSG Products generation)... Geometries in cache: 1 Geometry cache size in bytes: 728 CGAL Polyhedrons in cache: 0 CGAL cache size in bytes: 0 Compiling design (CSG Products normalization)... Normalized CSG tree has 0 elements Compile and preview finished. Total rendering time: 0 hours, 0 minutes, 0 seconds ``` - Revar > On Apr 13, 2019, at 7:03 PM, Revar Desmera <revarbat@gmail.com> wrote: > > Well THIS is interesting. I know I reproduced nop head's results with the version of OpenSCAD I'm running (2019-03-03) just a week or so ago. > But this code below does NOT reproduce it. > > - Revar > > >> On Apr 13, 2019, at 5:59 PM, Jordan Brown <openscad@jordan.maileater.net <mailto:openscad@jordan.maileater.net>> wrote: >> >> On 4/13/2019 5:37 PM, Revar Desmera wrote: >>> I suspect part of the delay isn't just search order, but that it's actually re-defining/recompiling the functions on each use. The fact that echo()s at top-level are executed any time a function in a used library is called, makes me suspect the function declarations are also being re-executed. >> >> With 2019.01-RC2 I don't see the behavior that you describe. >> >> I have a main file >> use <use.scad> >> >> foo(); >> translate([10,10]) foo(); >> echo(f(0)); >> and use.scad is: >> echo("top"); >> >> module foo() { >> cube(); >> } >> >> function f(n) = n+1; >> >> echo("bottom"); >> and the only echo output is the expected "ECHO: 1". >
RD
Revar Desmera
Sun, Apr 14, 2019 2:14 AM

Call foo() a few more times in main.scad, and you'll see the text echoed for every call.

  • Revar

On Apr 13, 2019, at 7:11 PM, Revar Desmera revarbat@gmail.com wrote:

Aha!  Minimal code to reproduce:
use.scad:

function foo(x) = x;
x=echo("DANGER DANGER! DANGER, Will Robinson!");

main.scad:

use <use.scad>
y = foo(2);

Output:

Used file cache size: 2 files
Compiling design (CSG Tree generation)...
ECHO: "DANGER DANGER! DANGER, Will Robinson!"
Compiling design (CSG Products generation)...
Geometries in cache: 1
Geometry cache size in bytes: 728
CGAL Polyhedrons in cache: 0
CGAL cache size in bytes: 0
Compiling design (CSG Products normalization)...
Normalized CSG tree has 0 elements
Compile and preview finished.
Total rendering time: 0 hours, 0 minutes, 0 seconds
  • Revar

On Apr 13, 2019, at 7:03 PM, Revar Desmera <revarbat@gmail.com mailto:revarbat@gmail.com> wrote:

Well THIS is interesting.  I know I reproduced nop head's results with the version of OpenSCAD I'm running (2019-03-03) just a week or so ago.
But this code below does NOT reproduce it.

  • Revar

On Apr 13, 2019, at 5:59 PM, Jordan Brown <openscad@jordan.maileater.net mailto:openscad@jordan.maileater.net> wrote:

On 4/13/2019 5:37 PM, Revar Desmera wrote:

I suspect part of the delay isn't just search order, but that it's actually re-defining/recompiling the functions on each use.  The fact that echo()s at top-level are executed any time a function in a used library is called, makes me suspect the function declarations are also being re-executed.

With 2019.01-RC2 I don't see the behavior that you describe.

I have a main file
use <use.scad>

foo();
translate([10,10]) foo();
echo(f(0));
and use.scad is:
echo("top");

module foo() {
cube();
}

function f(n) = n+1;

echo("bottom");
and the only echo output is the expected "ECHO: 1".

Call foo() a few more times in main.scad, and you'll see the text echoed for every call. - Revar > On Apr 13, 2019, at 7:11 PM, Revar Desmera <revarbat@gmail.com> wrote: > > Aha! Minimal code to reproduce: > use.scad: > ``` > function foo(x) = x; > x=echo("DANGER DANGER! DANGER, Will Robinson!"); > ``` > > main.scad: > ``` > use <use.scad> > y = foo(2); > ``` > > Output: > ``` > Used file cache size: 2 files > Compiling design (CSG Tree generation)... > ECHO: "DANGER DANGER! DANGER, Will Robinson!" > Compiling design (CSG Products generation)... > Geometries in cache: 1 > Geometry cache size in bytes: 728 > CGAL Polyhedrons in cache: 0 > CGAL cache size in bytes: 0 > Compiling design (CSG Products normalization)... > Normalized CSG tree has 0 elements > Compile and preview finished. > Total rendering time: 0 hours, 0 minutes, 0 seconds > ``` > > - Revar > > > >> On Apr 13, 2019, at 7:03 PM, Revar Desmera <revarbat@gmail.com <mailto:revarbat@gmail.com>> wrote: >> >> Well THIS is interesting. I know I reproduced nop head's results with the version of OpenSCAD I'm running (2019-03-03) just a week or so ago. >> But this code below does NOT reproduce it. >> >> - Revar >> >> >>> On Apr 13, 2019, at 5:59 PM, Jordan Brown <openscad@jordan.maileater.net <mailto:openscad@jordan.maileater.net>> wrote: >>> >>> On 4/13/2019 5:37 PM, Revar Desmera wrote: >>>> I suspect part of the delay isn't just search order, but that it's actually re-defining/recompiling the functions on each use. The fact that echo()s at top-level are executed any time a function in a used library is called, makes me suspect the function declarations are also being re-executed. >>> >>> With 2019.01-RC2 I don't see the behavior that you describe. >>> >>> I have a main file >>> use <use.scad> >>> >>> foo(); >>> translate([10,10]) foo(); >>> echo(f(0)); >>> and use.scad is: >>> echo("top"); >>> >>> module foo() { >>> cube(); >>> } >>> >>> function f(n) = n+1; >>> >>> echo("bottom"); >>> and the only echo output is the expected "ECHO: 1". >> >
NH
nop head
Sun, Apr 14, 2019 7:44 AM

I tried including my math functions into my sweep code instead of using
them. It made some of my tests very slightly faster and some slightly
slower. The downside of include is it has to re-parse the code each time
instead of using the module cache.

I don't really have any high frequency calls across file boundaries, which
is why I haven't noticed this effect. I haven't got anything approaching
the complexity of calculating a hull in user space. This got me thinking
that perhaps OpenSCAD should provide all the CSG ops as functions that take
parameters like polyhedron and return the same. That would allow geometry
to be computed without breaking anything. Of course if you called a union
or minkowski function it would make the compilation crazily slow.

Yes variables seem to re evaluated when you call a function in a used
module but I am sure functions and modules are not recompiled because that
is done at parse time and the AST is cached in the module cache. So there
isn't anything to do for a function unless it is called by a variable
initialisation.

On Sun, 14 Apr 2019 at 03:15, Revar Desmera revarbat@gmail.com wrote:

Call foo() a few more times in main.scad, and you'll see the text echoed
for every call.

  • Revar

On Apr 13, 2019, at 7:11 PM, Revar Desmera revarbat@gmail.com wrote:

Aha!  Minimal code to reproduce:
use.scad:

function foo(x) = x;
x=echo("DANGER DANGER! DANGER, Will Robinson!");

main.scad:

use <use.scad>
y = foo(2);

Output:

Used file cache size: 2 files
Compiling design (CSG Tree generation)...
ECHO: "DANGER DANGER! DANGER, Will Robinson!"
Compiling design (CSG Products generation)...
Geometries in cache: 1
Geometry cache size in bytes: 728
CGAL Polyhedrons in cache: 0
CGAL cache size in bytes: 0
Compiling design (CSG Products normalization)...
Normalized CSG tree has 0 elements
Compile and preview finished.
Total rendering time: 0 hours, 0 minutes, 0 seconds
  • Revar

On Apr 13, 2019, at 7:03 PM, Revar Desmera revarbat@gmail.com wrote:

Well THIS is interesting.  I know I reproduced nop head's results with the
version of OpenSCAD I'm running (2019-03-03) just a week or so ago.
But this code below does NOT reproduce it.

  • Revar

On Apr 13, 2019, at 5:59 PM, Jordan Brown openscad@jordan.maileater.net
wrote:

On 4/13/2019 5:37 PM, Revar Desmera wrote:

I suspect part of the delay isn't just search order, but that it's actually re-defining/recompiling the functions on each use.  The fact that echo()s at top-level are executed any time a function in a used library is called, makes me suspect the function declarations are also being re-executed.

With 2019.01-RC2 I don't see the behavior that you describe.

I have a main file

use <use.scad>

foo();
translate([10,10]) foo();
echo(f(0));

and use.scad is:

echo("top");

module foo() {
cube();
}

function f(n) = n+1;

echo("bottom");

and the only echo output is the expected "ECHO: 1".


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

I tried including my math functions into my sweep code instead of using them. It made some of my tests very slightly faster and some slightly slower. The downside of include is it has to re-parse the code each time instead of using the module cache. I don't really have any high frequency calls across file boundaries, which is why I haven't noticed this effect. I haven't got anything approaching the complexity of calculating a hull in user space. This got me thinking that perhaps OpenSCAD should provide all the CSG ops as functions that take parameters like polyhedron and return the same. That would allow geometry to be computed without breaking anything. Of course if you called a union or minkowski function it would make the compilation crazily slow. Yes variables seem to re evaluated when you call a function in a used module but I am sure functions and modules are not recompiled because that is done at parse time and the AST is cached in the module cache. So there isn't anything to do for a function unless it is called by a variable initialisation. On Sun, 14 Apr 2019 at 03:15, Revar Desmera <revarbat@gmail.com> wrote: > Call foo() a few more times in main.scad, and you'll see the text echoed > for every call. > > - Revar > > > > On Apr 13, 2019, at 7:11 PM, Revar Desmera <revarbat@gmail.com> wrote: > > Aha! Minimal code to reproduce: > use.scad: > ``` > function foo(x) = x; > x=echo("DANGER DANGER! DANGER, Will Robinson!"); > ``` > > main.scad: > ``` > use <use.scad> > y = foo(2); > ``` > > Output: > ``` > Used file cache size: 2 files > Compiling design (CSG Tree generation)... > ECHO: "DANGER DANGER! DANGER, Will Robinson!" > Compiling design (CSG Products generation)... > Geometries in cache: 1 > Geometry cache size in bytes: 728 > CGAL Polyhedrons in cache: 0 > CGAL cache size in bytes: 0 > Compiling design (CSG Products normalization)... > Normalized CSG tree has 0 elements > Compile and preview finished. > Total rendering time: 0 hours, 0 minutes, 0 seconds > ``` > > - Revar > > > > On Apr 13, 2019, at 7:03 PM, Revar Desmera <revarbat@gmail.com> wrote: > > Well THIS is interesting. I know I reproduced nop head's results with the > version of OpenSCAD I'm running (2019-03-03) just a week or so ago. > But this code below does NOT reproduce it. > > - Revar > > > On Apr 13, 2019, at 5:59 PM, Jordan Brown <openscad@jordan.maileater.net> > wrote: > > On 4/13/2019 5:37 PM, Revar Desmera wrote: > > I suspect part of the delay isn't just search order, but that it's actually re-defining/recompiling the functions on each use. The fact that echo()s at top-level are executed any time a function in a used library is called, makes me suspect the function declarations are also being re-executed. > > > With 2019.01-RC2 I don't see the behavior that you describe. > > I have a main file > > use <use.scad> > > foo(); > translate([10,10]) foo(); > echo(f(0)); > > and use.scad is: > > echo("top"); > > module foo() { > cube(); > } > > function f(n) = n+1; > > echo("bottom"); > > and the only echo output is the expected "ECHO: 1". > > > > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
MK
Marius Kintel
Sun, Apr 14, 2019 2:56 PM

On Apr 14, 2019, at 03:44, nop head nop.head@gmail.com wrote:

Yes variables seem to re evaluated when you call a function in a used module but I am sure functions and modules are not recompiled because that is done at parse time and the AST is cached in the module cache. So there isn't anything to do for a function unless it is called by a variable initialisation.

I  don't think that's necessary, and even if we continue doing it, it should be possible to perform some sort of Common Expression Elimination.
This probably went largely unnoticed since until the recently introduced echo() function, we didn't really have functions with side effects.

-Marius

> On Apr 14, 2019, at 03:44, nop head <nop.head@gmail.com> wrote: > > Yes variables seem to re evaluated when you call a function in a used module but I am sure functions and modules are not recompiled because that is done at parse time and the AST is cached in the module cache. So there isn't anything to do for a function unless it is called by a variable initialisation. > I don't think that's necessary, and even if we continue doing it, it should be possible to perform some sort of Common Expression Elimination. This probably went largely unnoticed since until the recently introduced echo() function, we didn't really have functions with side effects. -Marius
TP
Torsten Paul
Sun, Apr 14, 2019 4:39 PM

Also there's nothing to protect against performance regressions
at this point. While there's >1200 tests running on every code
change, that is only covering functional check.

So if we could collect a couple of not too big code examples
that could be used for performance testing the compilation /
evaluation steps, we could try to get that integrated into
the test suite and see if we can schedule that to run once
a day (or a week).

ciao,
Torsten.

Also there's nothing to protect against performance regressions at this point. While there's >1200 tests running on every code change, that is only covering functional check. So if we could collect a couple of not too big code examples that could be used for performance testing the compilation / evaluation steps, we could try to get that integrated into the test suite and see if we can schedule that to run once a day (or a week). ciao, Torsten.
NH
nop head
Sun, Apr 14, 2019 5:29 PM

To test my own library I time each test and store the results in a JSON
file. At the end of the test I show which got faster or slower by
significant amounts by showing the delta and colouring red and green and I
rank them by time. Here is the last run. As soon as I added this it
prompted me to start investigating how to make it go faster. It started at
972 seconds and now 172.3. It does vary a bit randomly as my PC is doing
other things. Perhaps the OpenSCAD test suite should do the same to
highlight how performance is changing.

[image: image.png]

On Sun, 14 Apr 2019 at 17:40, Torsten Paul Torsten.Paul@gmx.de wrote:

Also there's nothing to protect against performance regressions
at this point. While there's >1200 tests running on every code
change, that is only covering functional check.

So if we could collect a couple of not too big code examples
that could be used for performance testing the compilation /
evaluation steps, we could try to get that integrated into
the test suite and see if we can schedule that to run once
a day (or a week).

ciao,
Torsten.


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

To test my own library I time each test and store the results in a JSON file. At the end of the test I show which got faster or slower by significant amounts by showing the delta and colouring red and green and I rank them by time. Here is the last run. As soon as I added this it prompted me to start investigating how to make it go faster. It started at 972 seconds and now 172.3. It does vary a bit randomly as my PC is doing other things. Perhaps the OpenSCAD test suite should do the same to highlight how performance is changing. [image: image.png] On Sun, 14 Apr 2019 at 17:40, Torsten Paul <Torsten.Paul@gmx.de> wrote: > Also there's nothing to protect against performance regressions > at this point. While there's >1200 tests running on every code > change, that is only covering functional check. > > So if we could collect a couple of not too big code examples > that could be used for performance testing the compilation / > evaluation steps, we could try to get that integrated into > the test suite and see if we can schedule that to run once > a day (or a week). > > ciao, > Torsten. > > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
TP
Torsten Paul
Sun, Apr 14, 2019 5:35 PM

On 14.04.19 19:29, nop head wrote:

Perhaps the OpenSCAD test suite should do the same to highlight
how performance is changing.

Yes, that's pretty much what I'm thinking too. But as we run tests
on various machines it's not that simple as we don't want to have
lots of random errors flagged just because we got a slower worker
VM assigned for a build.

That's why I hope we might be able handle that using a couple of
specific test cases which have a reasonable long run time and
compare those against some base line tests. That way it would
only trigger notifications in case the relative time is changing
a lot and not absolute runtime.

ciao,
Torsten.

On 14.04.19 19:29, nop head wrote: > Perhaps the OpenSCAD test suite should do the same to highlight > how performance is changing. Yes, that's pretty much what I'm thinking too. But as we run tests on various machines it's not that simple as we don't want to have lots of random errors flagged just because we got a slower worker VM assigned for a build. That's why I hope we might be able handle that using a couple of specific test cases which have a reasonable long run time and compare those against some base line tests. That way it would only trigger notifications in case the relative time is changing a lot and not absolute runtime. ciao, Torsten.
M
MichaelAtOz
Sun, Apr 14, 2019 9:39 PM

nophead, what is that specific measure?
Elapsed run time for Render via cmd-line?


Admin - email* me if you need anything, or if I've done something stupid...

  • click on my MichaelAtOz label, there is a link to email me.

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.

The TPP is no simple “trade agreement.”  Fight it! http://www.ourfairdeal.org/  time is running out!

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

nophead, what is that specific measure? Elapsed run time for Render via cmd-line? ----- Admin - email* me if you need anything, or if I've done something stupid... * click on my MichaelAtOz label, there is a link to email me. Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above. The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out! -- Sent from: http://forum.openscad.org/
NH
nop head
Sun, Apr 14, 2019 11:28 PM

Yes I measure the time to preview a large PNG using the command line. It is
about 1.5 seconds slower than F5 preview but I am exporting a 4096 x 4096
image. I do that because viewall is quite conservative and leaves a large
border. I then use image magick to trim the border and downsize it to 1280
width to give some anti-aliasing. The results look like this.

[image: d_connectors.png]

On Sun, 14 Apr 2019 at 22:40, MichaelAtOz oz.at.michael@gmail.com wrote:

nophead, what is that specific measure?
Elapsed run time for Render via cmd-line?


Admin - email* me if you need anything, or if I've done something stupid...

  • click on my MichaelAtOz label, there is a link to email me.

Unless specifically shown otherwise above, my contribution is in the
Public Domain; to the extent possible under law, I have waived all
copyright and related or neighbouring rights to this work. Obviously
inclusion of works of previous authors is not included in the above.

The TPP is no simple “trade agreement.”  Fight it!
http://www.ourfairdeal.org/  time is running out!

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


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

Yes I measure the time to preview a large PNG using the command line. It is about 1.5 seconds slower than F5 preview but I am exporting a 4096 x 4096 image. I do that because viewall is quite conservative and leaves a large border. I then use image magick to trim the border and downsize it to 1280 width to give some anti-aliasing. The results look like this. [image: d_connectors.png] On Sun, 14 Apr 2019 at 22:40, MichaelAtOz <oz.at.michael@gmail.com> wrote: > nophead, what is that specific measure? > Elapsed run time for Render via cmd-line? > > > > ----- > Admin - email* me if you need anything, or if I've done something stupid... > > * click on my MichaelAtOz label, there is a link to email me. > > Unless specifically shown otherwise above, my contribution is in the > Public Domain; to the extent possible under law, I have waived all > copyright and related or neighbouring rights to this work. Obviously > inclusion of works of previous authors is not included in the above. > > The TPP is no simple “trade agreement.” Fight it! > http://www.ourfairdeal.org/ time is running out! > -- > Sent from: http://forum.openscad.org/ > > _______________________________________________ > OpenSCAD mailing list > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
M
MichaelAtOz
Sun, Apr 14, 2019 11:53 PM

Noting, for others, that nophead uses render(), so cmd-line preview includes
the CGAL processing.


Admin - email* me if you need anything, or if I've done something stupid...

  • click on my MichaelAtOz label, there is a link to email me.

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above.

The TPP is no simple “trade agreement.”  Fight it! http://www.ourfairdeal.org/  time is running out!

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

Noting, for others, that nophead uses render(), so cmd-line preview includes the CGAL processing. ----- Admin - email* me if you need anything, or if I've done something stupid... * click on my MichaelAtOz label, there is a link to email me. Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. Obviously inclusion of works of previous authors is not included in the above. The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out! -- Sent from: http://forum.openscad.org/