scan_data: defer escape.swissfel import to where it's actually used
from escape.swissfel import load_dataset_from_scan sat at module level in RunData's own module, which eco.elements.assembly imports (for the run_status_convenience decorator) - i.e. every `import eco` pulls it in, transitively dragging in escape's whole dask/pandas/scipy/IPython/xarray stack (~14s on this NFS-mounted env) even when nothing ever loads a run. Found while looking into why eco.status_server.gui's "no eco namespace import... starts in under a second" claim wasn't holding: `from .client import StatusServerClient` still runs eco/__init__.py first regardless of what .client itself imports. Moving this one import into the single method that actually calls load_dataset_from_scan cuts `from eco. status_server.client import StatusServerClient` from ~19s to ~7.5s cold, and plain `import eco` likewise - benefits every eco import, not just the status-server GUI. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e996b31500
commit
e4e31f2a97
1 file changed
+11
-1
@@ -1,7 +1,6 @@
|
||||
from numbers import Number
|
||||
import os
|
||||
from pathlib import Path
|
||||
from escape.swissfel import load_dataset_from_scan
|
||||
|
||||
# from eco.elements.assembly import Assembly
|
||||
import json
|
||||
@@ -41,6 +40,17 @@ class RunData:
|
||||
return runs
|
||||
|
||||
def load_run(self, run_number, **kwargs):
|
||||
# Deferred: escape.swissfel eagerly imports dask/pandas/scipy/
|
||||
# IPython/xarray (~14s on a cold NFS-mounted env), and this module
|
||||
# is reached from eco.elements.assembly - i.e. from `import eco`
|
||||
# itself - so a module-level import here made that cost mandatory
|
||||
# for literally every eco import, not just the one RunData method
|
||||
# that actually loads a dataset. See eco.status_server.gui, whose
|
||||
# own docstring claims "no eco namespace import... starts in under
|
||||
# a second" - not true before this, since `from .client import
|
||||
# StatusServerClient` still runs eco/__init__.py first regardless.
|
||||
from escape.swissfel import load_dataset_from_scan
|
||||
|
||||
if run_number < 0:
|
||||
run_number = self.get_available_run_numbers()[run_number]
|
||||
print(f"Loading run number {run_number}")
|
||||
|
||||
Reference in new issue
Block a user