Reduce the time taken to import `cf`
Importing cf is quite slow ... on my local computer it takes 2 seconds.
There seem to be two main culprits for the slow import:
- Doc string rewriting
- At import time, every docstring (of which there are currently 5569) is inspected for doc string substitutions, replacing any that are found
- Importing external modules that themselves have a slow import
- The main problems here are
dask,scipy,s3fs,zarr,h5netcdf,uritools,netCDF4
- The main problems here are
These can be improved on:
- Doc string rewriting
- Handled in
cfdm: Reduce the time taken to importcfdmcfdm#361
- Handled in
- Importing external modules that themselves have a slow import
- Move the imports to run time, rather than import time. Also import a lot of this from
cfdm. Many will not ever get imported, and when they do, the time is usually negligible compared to the operation being run.
- Move the imports to run time, rather than import time. Also import a lot of this from
Results
By applying these changes, my local import time reduces to 0.25 seconds (from 2 seconds - a factor of 6 speed-up).
PR to follow