Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to speed up an import?

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?

like image 720
orlp Avatar asked Sep 15 '15 19:09

orlp


1 Answers

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.

like image 140
Alfe Avatar answered Sep 28 '22 22:09

Alfe