Does importing too many classes (definitions) can make the execution much longer?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
stefankorisnik3
Posts: 101
Joined: Sun Jul 24, 2022 12:49 pm

Does importing too many classes (definitions) can make the execution much longer?

Post by stefankorisnik3 »

Does importing too many classes (just declarations nothing executable) can make execution of FreeCAD python program much longer?
chrisb
Veteran
Posts: 53930
Joined: Tue Mar 17, 2015 9:14 am

Re: Does importing too many classes (definitions) can make the execution much longer?

Post by chrisb »

As soon as it is enough to need slower memory, e.g. swap space on a hard disc, it will make a program slower.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Does importing too many classes (definitions) can make the execution much longer?

Post by TheMarkster »

I don't think it matters so much in terms of execution time after all the imports are done, but I haven't tested it. You would need to do some profiling to see for sure. Obviously, the imports themselves will take some time to do, which can be quite noticeable if there are many packages to be imported. If all the packages are not needed every time the script is executed, then it can be sensible to do the imports only as needed rather than importing everything upon startup at the top of the source code.
Post Reply