Freecad fails to be serious CAD because of poor language choice

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
andremiv
Posts: 56
Joined: Thu Sep 02, 2021 10:45 am
Location: France

Freecad fails to be serious CAD because of poor language choice

Post by andremiv »

Hello,

I have inscribed myself few month ago, just to tell how bad freecad was. Then I tried all the damn CAD, I finally recognized Freecad as the least worst of them all. "not so bad", maybe even "good" after the disastrous start. But Now I am still angry because the devs chose C++ or python. When you have 4000+ points, the program is so slow, it is so disappointing because freecad could be much more if it was written in C. Instead of being slow at 4000 points it would be slow only at 400000 points. I was so disappointed that I wrote my own software in C to create double enveloping worm gears with custom tooth profile. I generate 10⁶ faces instantly. I tried to load my double envelopping worm gear in Freecad and no surprises there, the software is too slow !

I think the opensource community needs a serious CAD written in C to be speedy. I do not want to start a project from scratch, I just want to speed up some fonctions in Freecad to make them 100x times faster.

Is anybody interested ? The idea is only to replace python function with binary calls coming from optimized C code. Of course we have to write new API but if the python code base is good, the translation of the ideas in C should not be a problem and be relativeley fast.

For now I am stuck using zero CAD, i use pure C code to generate my points and STL files. That sucks but it seems there is no CAD that is fast enough for my liking. Freecad has nice feature but unusable because too slow.

I seriously think freecad being able to manipulate 10⁶ points should be a priority for any serious CAD because 10⁴ points and python is a joke.

Is the community angry as me ? I am the only one unhappy with the situation ? Pls share you through on an accelerated C api for freecad.

Miville André
Last edited by andremiv on Wed Jan 26, 2022 11:12 pm, edited 2 times in total.
A new era of point programmation has come !
chrisb
Veteran
Posts: 53922
Joined: Tue Mar 17, 2015 9:14 am

Re: Freecad fails to be serious CAD because of poor language choice

Post by chrisb »

We had a very similar discussion recently. The point is, that usually not the Python code is the bottleneck, nor the FreeCAD code written in C++. It is rather the OCC geometric kernel. So if you can go ahead and replace it with fast C and a similar API, it would probably be highly appreciated.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Freecad fails to be serious CAD because of poor language choice

Post by onekk »

Sometimes it is not the geometric kernel that is slow, is the way you instruct him to do things that are wrong and involve some difficult calculation or some "race conditions" that slow down things.

Maybe submitting some of your work, will reveal that maybe you have tried to use some "malformed objects" to do complex things, like Loft and Sweep, that are know to be problematics and very slow when used without some "caveats":

Probably there are better ways to code something in FreeCAD, but I think that if you have code something that deal with graphics, you will easily see that are involved many calculations, and some of them involve, matrices or even more complex things.

As OCCT is used in some "professional environment" maybe the key point is "how other program that use OCCT" address problems that are critical in FreeCAD.

Sadly many of them are "closed source" so it is not easy to analyze "how things are done".

One other thing, as FreeCAD is increasing his user base, it has not to be "so bad", if it will not fit you needs, simply don't use it, if you have some "concrete" proposal, "start submitting code" and analyze "why" things are so slow.


Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Freecad fails to be serious CAD because of poor language choice

Post by wmayer »

But Now I am still angry because the devs chose C++ or python. When you have 4000+ points, the program is so slow, it is so disappointing because freecad could be much more if it was written in C.
Do you have any serious proof that C would be faster than C++?

Of course Python is slower than C or C++ but in most cases it acts as a small wrapper with only little overhead. The time consuming part in most cases is still written in C++. There might be a handful of algorithms that are entirely written in Python and porting them to C++ would make them a lot faster. But this really applies to very few functions.
Instead of being slow at 4000 points it would be slow only at 400000 points.
When you talk about 4000+ points how do you create them? Is each point represented by an own object in a document or do you create one object with all points. This makes the difference and not the chosen language. The bottleneck when creating an object for each point is the scenegraph because traversing it is very time consuming.
I was so disappointed that I wrote my own software in C to create double enveloping worm gears with custom tooth profile. I generate 10⁶ faces instantly. I tried to load my double envelopping worm gear in Freecad and no surprises there, the software is too slow !
What is slow? The loading? The rendering?
andremiv
Posts: 56
Joined: Thu Sep 02, 2021 10:45 am
Location: France

Re: Freecad fails to be serious CAD because of poor language choice

Post by andremiv »

Ok makes sense chrisb, I will study the OCCT library, look at their implementation, see how they solve the problems and look at how you call their functions. There is definitely room for improvement if other proprietary CAD are faster. For my current need, I would like to dig holes, put rayons on my globoid worm gear for post processing for 3d printing without having to manually program it in C. I tried to convert my half millions faces STL into shape object but freecad is too long for the task. The wheel has 150 teeth 1 meter diameter and large so great number of points, I can't reduce the number of faces sufficiently for freecad to be happy. For now I will stick to generate rayons and holes in C for the wheel and worm.
A new era of point programmation has come !
chrisb
Veteran
Posts: 53922
Joined: Tue Mar 17, 2015 9:14 am

Re: Freecad fails to be serious CAD because of poor language choice

Post by chrisb »

Instead of converting from STL to FreeCAD, it is often faster to remodel it from scratch. And on top it is of better quality because it is no longer tesselated. For gears you can have a look at the built in PartDesign involute gears or use the addon FCGears workbench.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
andremiv
Posts: 56
Joined: Thu Sep 02, 2021 10:45 am
Location: France

Re: Freecad fails to be serious CAD because of poor language choice

Post by andremiv »

I tried FCgears but there was no double enveloping globoid worm gear pair generator, a constructive geometry method can be used to construct them but I was not able to implement it in Freecad because I am still Freecad noob, . see here the method : https://www.thingiverse.com/thing:2776688 but I was not happy with his method for the gear teeth profile, I wanted something more flexible, so why not let the user provide tooth profile : https://www.desmos.com/calculator/yrihyyn5ek, then compute the worm screw from profile, then compute the gear from the screw. For having used freecad on many attempts, I know for sure that my C code is at the very least 100x times faster to do the tasks so I will dig some more to understand why freecad is so slow. I need this for an heliostat transmission with less than 1/100° of backlash, not for power transmission. I will try to 3d print them :D
Do you have any serious proof that C would be faster than C++?
it is 2 times faster on average (for same algo in C vs C++), compiles 10 times faster, way more easier language (less complex) and while being memory and space friendly. I was always amazed by the power of C++ but the language proved too hard for me and I had difficulty understanding what the code was doing behind myback whereas with the good old C89, you always know what it is doing, the language is dumb yet very efficient, so much simpler ! Love it !

I have no problem with C++ by the way, that ' s so much better than python

Code: Select all

Of course Python is slower than C or C++ but in most cases it acts as a small wrapper with only little overhead. The time consuming part in most cases is still written in C++. 
Python is between 100 and 1000 times slower than C (no jokes), So admit you have N points so a python scripts call N times a C++ function, then I would have found the culprit. the python base code including a call loop . Also File IO in python is hell slow ! I remember opening a file in python to parse basic content for university project, I was raging because of the slowness so I decided to make all file IO in C because it is simpler and 1000 times faster, personnaly that's the last time I have ever used python for anything else but the matplotlib to enable you to make nice plots. I will dig to see where most of the speed up can be made, but from my experience, when I heard python, there is PTSD that comes right back.

After looking vaguely the occt kernel repo, the reputation and seriousness I am pretty confident (no offense) that the python is most certainly the problem and not the underlying occt kernel.
Also because I used cloud compute program which also use occt and is way faster.

I know it should be hardbroking to say that python is maybe the issue, especially for the guys that wrote freecad python code but let me time to prove it, and if I am right, pls don't be afraid to port it in C++ or C, see it as a change for the good, the call for a serious open source CAD that is fast, the best CAD freecad always needed to be !
A new era of point programmation has come !
andremiv
Posts: 56
Joined: Thu Sep 02, 2021 10:45 am
Location: France

Re: Freecad fails to be serious CAD because of poor language choice

Post by andremiv »

Ok I just had a look into freecad's repo. 50% c++, 45% python : https://github.com/FreeCAD/FreeCAD

Frankly it is nightmarish, C++ code seems interconnected with python arguments. Seriously why not pick one language only ? I lack skills in C++ and python concepts. I am sure I will not be able to help you. I wish all freecad features were 100 times faster. That when you click OK, you get a near instant answer.

It seems spagehtti programming hell for me. I have read obfuscated uncommented C chess engines that looks way more understandable than this. Sorry for the help I was supposed to give you but I think I will stick to my loser ZERO CAD with direct C programming. But I will never forget what freecad was offering me with low points count. Don't have money to buy other CAD and I had way horrible experience with the other commercial CAD.

Wish you all the best the freecad dev team ! Make the dream come true !

André Miville
A new era of point programmation has come !
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Freecad fails to be serious CAD because of poor language choice

Post by Kunda1 »

I'm ready to see some benchmarks to backup your opinions/observations, @andremiv
Let us know when you have those.
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Freecad fails to be serious CAD because of poor language choice

Post by TheMarkster »

LOL. "I looked at your code and I can't make heads or tails of it, but you guys are doing it all wrong."
Post Reply