EasyScience / EasyDiffractionApp

Diffraction data analysis application
https://easydiffraction.org
BSD 3-Clause "New" or "Revised" License
4 stars 1 forks source link

Startup profiling #193

Open rozyczko opened 2 years ago

rozyczko commented 2 years ago

eDA startup is very long. It should be time profiled and optimized.

rozyczko commented 2 years ago

Analysis with py-spy.

Total startup time: 9.28s, out of which:

easyCore

easyCore\easyCore\__init__.py:11
import pint

takes 2.20s

easyCore\easyCore\Fitting\__init__.py:11
from lmfit import Parameter as lmParameter, Parameters as lmParameters, Model as lmModel

takes 1.41s

easyCore\easyCore\Fitting\fitting_template.py:15
from scipy import stats

takes 1.04s

cryspy

cryspy\cryspy\A_functions_base\function_3_mcif.py:718
read_magnetic_data()

takes 3.78s

Total of above 4 calls/imports is 8.43s constituting 91% of the startup time

rozyczko commented 2 years ago

This startup analysis file should be opened by the speedscope app: https://www.speedscope.app/

startup2.log

rozyczko commented 2 years ago

On average, importing cryspy takes 4.25s while GSASII takes about 1.5s (locally).

It would be good to replace the calculator check in easyDiffractionLib\easyDiffractionLib\Interfaces\__init__.py with a check that does not directly import those modules. However, this check also does quite a bit of setting up the interfaces, so it won't be as easy. Postponing the actual calculator import, e.g. in Calculators\cryspy.py:7 would also be an option.

rozyczko commented 2 years ago

Loading cryspy can't be made lazy since the calculators are all instantiated on startup. Similarly, lazy loading of lmfit and pint can't be easily achieved due to immediate instantiation.

The only module which can be shifted to on-demand load is bumps and scipy. This should shave a couple of seconds off the loading time.

rozyczko commented 2 years ago

Also, improved performance by making the profile update run only once for

This should be helpful