From 542f949fa0a76df81aa9de7beb6f084ad5815a02 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Sat, 4 Apr 2026 22:53:50 +0200 Subject: [PATCH] Use local variable to avoid attribute lookup in form_rxn_matrix loop (#3884) Co-authored-by: Perry Co-authored-by: Paul Romano --- openmc/deplete/chain.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/openmc/deplete/chain.py b/openmc/deplete/chain.py index 514f8ed225..97ec8d9618 100644 --- a/openmc/deplete/chain.py +++ b/openmc/deplete/chain.py @@ -701,15 +701,19 @@ class Chain: if fission_yields is None: fission_yields = self.get_default_fission_yields() + # Save local variables to avoid attribute lookups in loop + index_nuc = rates.index_nuc + index_rx = rates.index_rx + for i, nuc in enumerate(self.nuclides): - if nuc.name not in rates.index_nuc: + if nuc.name not in index_nuc: continue - nuc_ind = rates.index_nuc[nuc.name] + nuc_ind = index_nuc[nuc.name] nuc_rates = rates[nuc_ind, :] for r_type, target, _, br in nuc.reactions: - r_id = rates.index_rx[r_type] + r_id = index_rx[r_type] path_rate = nuc_rates[r_id] # Loss term -- make sure we only count loss once for