Skip to content

Commit

Permalink
Fix slowness of loading large experiment lists due to pkg_resources->…
Browse files Browse the repository at this point in the history
…importlib change
  • Loading branch information
jbeilstenedmands committed Aug 22, 2023
1 parent 9657a16 commit 7d236a6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions newsfragments/XXX.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix slowness of loading large experiment lists with profile/scaling models
7 changes: 6 additions & 1 deletion src/dxtbx/model/experiment_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ class InvalidExperimentListError(RuntimeError):
"""


scaling_model_entry_points = importlib.metadata.entry_points()[
"dxtbx.scaling_model_ext"
]


class FormatChecker:
"""A helper class to speed up identifying the correct image format by first
trying the last format that was used."""
Expand Down Expand Up @@ -576,7 +581,7 @@ def _lookup_model(self, name, experiment_dict):
@staticmethod
def _scaling_model_from_dict(obj):
"""Get the scaling model from a dictionary."""
for entry_point in importlib.metadata.entry_points()["dxtbx.scaling_model_ext"]:
for entry_point in scaling_model_entry_points:
if entry_point.name == obj["__id__"]:
return entry_point.load().from_dict(obj)

Expand Down
4 changes: 3 additions & 1 deletion src/dxtbx/model/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import importlib.metadata
import logging

profile_entry_points = importlib.metadata.entry_points()["dxtbx.profile_model"]


class ProfileModelFactory:
"""
Expand All @@ -16,7 +18,7 @@ def from_dict(obj):
"""
if obj is None:
return None
for entry_point in importlib.metadata.entry_points()["dxtbx.profile_model"]:
for entry_point in profile_entry_points:
if entry_point.name == obj["__id__"]:
return entry_point.load().from_dict(obj)
logging.getLogger("dxtbx.model.profile").warn(
Expand Down

0 comments on commit 7d236a6

Please sign in to comment.