Skip to content

Commit 61bd2fe

Browse files
emoltertapastro
andauthored
JP-4127: Improve association generator runtime (#10384)
Co-authored-by: Tyler Pauly <tapastro@gmail.com>
1 parent 297b30f commit 61bd2fe

4 files changed

Lines changed: 20 additions & 3 deletions

File tree

changes/10384.associations.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Bypass unnecessary compare_asns calls to improve generator runtime. Factor-of-3 runtime improvement is realized for one large NRC_WFSS pool tested

jwst/associations/generator/generate.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,16 @@ def match_item(item, associations):
215215
List of process events.
216216
"""
217217
item_associations = []
218+
seen_ids = set()
218219
process_list = []
219220
for asn in associations:
220-
if asn in item_associations:
221+
# Can't use just `if asn in item_associations` because this triggers compare_asns call
222+
# and is slow.
223+
if id(asn) in seen_ids:
221224
continue
222225
matches, reprocess = asn.add(item)
223226
process_list.extend(reprocess)
224227
if matches:
225228
item_associations.append(asn)
229+
seen_ids.add(id(asn))
226230
return item_associations, process_list

jwst/associations/lib/dms_base.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,18 @@ def from_items(self):
392392
items = []
393393
return items
394394

395+
@property
396+
def item_ids(self):
397+
"""
398+
Set of all item IDs in all products of this association.
399+
400+
Returns
401+
-------
402+
set
403+
Set of item IDs.
404+
"""
405+
return {item["filename"] for item in self.from_items}
406+
395407
@property
396408
def member_ids(self):
397409
"""
@@ -497,7 +509,7 @@ def is_item_member(self, item):
497509
bool
498510
True if item is a member.
499511
"""
500-
return item in self.from_items
512+
return item["filename"] in self.item_ids
501513

502514
def is_item_ami(self, item):
503515
"""

jwst/associations/tests/test_dms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def dms_registry():
2222
@pytest.fixture(scope="module")
2323
def dms_asns(dms_registry):
2424
"""Create basic associations"""
25-
result = dms_registry.match("item")
25+
result = dms_registry.match({"filename": "item.fits"})
2626
return result
2727

2828

0 commit comments

Comments
 (0)