desihub / desispec

DESI spectral pipeline
BSD 3-Clause "New" or "Revised" License
36 stars 24 forks source link

improve top-level import speed with deferred imports #2394

Open sbailey opened 1 month ago

sbailey commented 1 month ago

This PR addresses several import speed issues identified in #2379, especially for desispec.io.

desispec.io: deferring imports of specutils, speclite.filters, and desispec.preproc improves "import desispec.io" from 4.1 seconds to 1.3 seconds (best of 5, pwd on scratch). The remaining time is dominated by importing astropy.table (1.0 sec), which would be messy to defer everywhere.

desispec.tsnr: deferring import astropy.convolution improves "import desispec.tsnr" from 2.9 to 2.3 sec. Remaining big imports are astropy.table and astropy.coordinates via desiutil.dust.

desispec.pixgroup: removing unused import healpix improves "import desispec.pixgroup" from 3.7 to 3.15 sec. Remaining big imports are desispec.tsnr (could be deferred, though this is a bit messy since TSNR is re-calculated on-the-fly if columns are missing from older data)

coveralls commented 1 month ago

Coverage Status

coverage: 30.186% (-0.006%) from 30.192% when pulling 5fabf40d68b9358e8f8ed2dec54b113d45faf5ea on import_speed into 05bcd762c29d826fd39c6e9378e9355760e8a939 on main.