CoffeeSCad icon indicating copy to clipboard operation
CoffeeSCad copied to clipboard

Rendering Speed

Open Daubsy opened this issue 12 years ago • 12 comments

I am working on a complex model. When I make changes, it takes a very long time for the scene to update.

Will local development provide faster rendering speed? Are there any other development tools / workflows that can help with this?

Thanks!

Daubsy avatar Jul 16 '13 18:07 Daubsy

Your question is stated in quite vague terms. I suppose you don't refer to the speed of WebGL rendering your model, but to the speed with wich CoffeeSCad rebuilds your model after changing parameters.

I did some tests with OpenJSCad and found at that a lot of the time is spend in the boolean operations due to the model being canonicalized and tessellated. I see that CoffeeSCad reused this code (without mentioning the original author in the licence though? but I don't know a thing about licencing though..) so you will have the same speed issues there.

Even one union on a model with many polygons or vertices will take a substantial amount of time. I suspect doing the tesselation in c++ (or opengl 4.0 .. not supported by webbrowsers) will be quicker. But if we do it with javascript, it doesn't matter if you do it in the browser or locally. Both use the same javascript engine (V8 or SpiderMonkey) on the same machine.

For the workflow: You could split your model and code into parts, and only build and render the parts your working on. But this will not speed up the build times of your complete model, it will only make working on large models easier.

You can also try to not rebuild your complete model on every parameter change. Rather split your code into parts that are evaluated in consecutive order, and have parameters for each part. Then, on parameter change, you don't have to evaluate the code that belongs to earlier parts, but only for the parts that follow after parameter change. Then you might try to do the union operations, or other operations that trigger heavy computation, early in your code, and have parameters that do very simple transformations later in the code...

In pseudo code, imagine the speed you might gain when you only execute the code that is needed for the parameter change:

var doAll = function(param1, param2){
     operation1(param1);
     operation2(param2);     
};
doAll( value1, value2 ); // initially
doAll( value1, value2 ); // on value2 change
var doFirst = function(param1){
     operation1(param1);
};
var doSecond = function(param2){
      operation2(param2);
};
doFirst( value1 );
doSecond (value2); //initially
doSecond (value2); // on value2 change

Can you maybe comment about what slows you down?

MauricevanLeeuwen avatar Jul 24 '13 13:07 MauricevanLeeuwen

Very complete and correct answer by @MauricevanLeuwen :-)

Spliting things into smaller units / projects helps in this case, but only to a point.

If you could post you code somewhere it would really help with diagnosing the issue more precisely :-)

I am also working on a number of optilisations which should help :

  • only auto reconpile on actual code change (ignore change in comments etc)
  • partial recompiling : coffeescad would only recompile the parts that actually changed
  • geometry instancing : if you put the SAME objects multiple times into the project it would only get computed once
  • improved multithreading (overall speed up)

But these improvements are still a few months off (pessimistically)

kaosat-dev avatar Jul 24 '13 15:07 kaosat-dev

Also @MauricevanLeeuwen The fact that coffeescad is/was based on openjscad is clearly stated in the readme :so ;-)

kaosat-dev avatar Jul 24 '13 16:07 kaosat-dev

Woops you meant in the licence file ? Yeah not sure either could add Openjscad's author I guess / other libs too ( lots of them).

kaosat-dev avatar Jul 24 '13 16:07 kaosat-dev

Thank you for the informative answers! I don't think WebGL processing is the problem. The rendering speed seems mostly affected by number of objects and boolean operations. Even if I change a very insignificant property, Coffeescad takes a long time to update the model (although I guess this could also be the result of poor coding?). I have built a similar model in OpenJScad and it renders and updates much faster when I make changes. Does converting from Coffeescript to Javascript at compile have a significant impact?

Daubsy avatar Jul 25 '13 16:07 Daubsy

I'm interested in your code. Could you give an example of code that runs (much) faster in OpenJSCad than CoffeeSCad ?

MauricevanLeeuwen avatar Jul 25 '13 17:07 MauricevanLeeuwen

Sure. Im doing something very similar to the gear demo. Try running this code in Coffeescad: https://github.com/zignig/CoffeeSCad-examples/tree/master/applied/Involute

It was adapted from the OpenJScad gear example "Greg's Parametric Involute Gear Script" at openjscad,org, which takes no more than 2 seconds to render. The similar Coffeescad example take almost a minute to render. That has been my experience.

Daubsy avatar Jul 25 '13 17:07 Daubsy

@Daubster I believe it is not 100% the same code, will check in details, but also, can you please confirm that you have also tried enabling "background processing" in CoffeeSCad ? The conversion time coffee-> js is trivial (not even a few ms in most cases)

kaosat-dev avatar Jul 25 '13 18:07 kaosat-dev

@MauricevanLeeuwen , anyway I can contact you by mail? I got a few things I would love to discuss :)

kaosat-dev avatar Jul 25 '13 18:07 kaosat-dev

@kaosat-dev see my Gravatar to see my contact info. (start a google hangout)

MauricevanLeeuwen avatar Jul 26 '13 19:07 MauricevanLeeuwen

@kaosat-dev found the contact details yet? If you don't want to use google hangouts, what's your preferred alternative?

MauricevanLeeuwen avatar Jul 30 '13 11:07 MauricevanLeeuwen

@MauricevanLeeuwen sorry about that, had a very busy weekend, thanks for the contact info , added you on g+ (I generally don't use hangouts, but single person message on g+ if that is alright with you :)

kaosat-dev avatar Jul 30 '13 11:07 kaosat-dev