I have a CLI application that requires sympy
. The speed of the CLI application matters - it's used a lot in a user feedback loop.
However, simply doing import sympy
takes a full second. This gets incredibly annoying in a tight feedback loop. Is there anyway to 'preload' or optimize a module when a script is run again without a change to the module?
Obviously sympy
does a lot when being imported. It could be initialization of internal data structures or similar. You could call this a flaw in the design of the sympy
library.
Your only choice in this case would be to avoid redoing this initialization.
I assume that you find this behavior annoying because you intend to do it often. I propose to avoid doing it often. A way to achieve this could be to create a server which is started just once, imports sympy
upon its startup, and then offers a service (via interprocess communication) which allows you to do whatever you want to do with sympy
.
If this could be an option for you, I could elaborate on how to do this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With