caching code ?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

caching code ?

codifies
Just thinking out loud here I have no idea if it would help or its even
practical....

but suppose I have a small frequently used module like this

module drain() {

     difference() {
         translate([0,0,1]) cylinder(r=4,h=2,center=true,$fn=32);
         rotate_extrude(convexity = 10,$fn=32)
             translate([4, 0, 0])
                 circle(r = 2,$fn=32);
     }
     translate([0,0,-7]) cylinder(h=8,r=2,$fn=32);
}


then suppose I could modify it like this

module drain() {
cache() {
         difference() {
             translate([0,0,1]) cylinder(r=4,h=2,center=true,$fn=32);
                 rotate_extrude(convexity = 10,$fn=32)
                      translate([4, 0, 0])
                           circle(r = 2,$fn=32);
          }
           translate([0,0,-7]) cylinder(h=8,r=2,$fn=32);
}
}

the interpreter would hash just the code between the curly braces (such
the code could change location without disturbing the hash) the hash
would invalidate the cache if there were any changes in the code

The cache would produce ready a made mesh for faster use....

of course this doesn't help with chunks of code that are parameter
driven (except maybe simple translations) but allowing the user to cache
bits like this might make some difference....



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: caching code ?

nophead
If you replace cache with render then the mesh will be cached and only recalculated when parameters change.

On 10 February 2018 at 10:57, Chris Camacho <[hidden email]> wrote:
Just thinking out loud here I have no idea if it would help or its even practical....

but suppose I have a small frequently used module like this

module drain() {

    difference() {
        translate([0,0,1]) cylinder(r=4,h=2,center=true,$fn=32);
        rotate_extrude(convexity = 10,$fn=32)
            translate([4, 0, 0])
                circle(r = 2,$fn=32);
    }
    translate([0,0,-7]) cylinder(h=8,r=2,$fn=32);
}


then suppose I could modify it like this

module drain() {
cache() {
        difference() {
            translate([0,0,1]) cylinder(r=4,h=2,center=true,$fn=32);
                rotate_extrude(convexity = 10,$fn=32)
                     translate([4, 0, 0])
                          circle(r = 2,$fn=32);
         }
          translate([0,0,-7]) cylinder(h=8,r=2,$fn=32);
}
}

the interpreter would hash just the code between the curly braces (such the code could change location without disturbing the hash) the hash would invalidate the cache if there were any changes in the code

The cache would produce ready a made mesh for faster use....

of course this doesn't help with chunks of code that are parameter driven (except maybe simple translations) but allowing the user to cache bits like this might make some difference....



_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: caching code ?

JordanBrown
On 2/10/2018 3:30 AM, nop head wrote:
If you replace cache with render then the mesh will be cached and only recalculated when parameters change.

Doesn't it do that even if you don't call render()?  I don't use render() much, yet it still tells me how much memory is being used by the cache.


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: caching code ?

codifies

whatever its actually doing it defiantly saves significant time even on half a dozen relatively simple shapes, so from now on I'll definitely be keeping in mind where I might be able to use it...

On 10/02/18 15:27, Jordan Brown wrote:
On 2/10/2018 3:30 AM, nop head wrote:
If you replace cache with render then the mesh will be cached and only
recalculated when parameters change.
Doesn't it do that even if you don't call render()?  I don't use
render() much, yet it still tells me how much memory is being used by
the cache.




_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org