From e4e31f2a97339083743aeec69b5dc0a8132f34f8 Mon Sep 17 00:00:00 2001 From: lemke_h Date: Fri, 16 Oct 2026 10:59:55 +0200 Subject: [PATCH] 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 --- eco/acquisition/scan_data.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/eco/acquisition/scan_data.py b/eco/acquisition/scan_data.py index e33bd3b..859f26e 100644 --- a/eco/acquisition/scan_data.py +++ b/eco/acquisition/scan_data.py @@ -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}")