pcdshub / pcdscalc

PCDS control system-agnostic scientific calculation routines
Other
0 stars 6 forks source link

MAINT: delay xraydb import for import speed concerns #17

Closed ZLLentz closed 2 years ago

ZLLentz commented 2 years ago

Description

Delay the xraydb import until it is first used.

Motivation and Context

Importing xraydb is slow and is not guaranteed to be used on execution of the progam. Yes, the most useful calculations here all route through it, but consider the cases where:

  1. we create lens devices in pcdsdevices for in/out control without doing calcs
  2. we want to use the other calcs in here that don't need xraydb

If it was just item 1 I would want to do this in pcdsdevices, but since there are methods in here that don't intersect xraydb I think it's appropriate to do it in this module.

The speedup is about 0.7s for applications that don't use these methods, so it's probably worth it.

The reason we have a speedup is because xraydb imports sqlalchemy which has a slow import, among other things.

How Has This Been Tested?

Interactively only Tests still pass locally

Where Has This Been Documented?

N/A

ZLLentz commented 2 years ago

CI failure is pre-commit failures- this repo hasn't been touched since we updated our CI to run the pre-commit checks. I'll handle that before seeking a merge here, probably in a separate PR tomorrow.

ZLLentz commented 2 years ago

rebased on top of the pre-commit update PR