From 67fc0708e55e90fcc20672fecedd737292aefd80 Mon Sep 17 00:00:00 2001 From: Dan Nealschneider Date: Wed, 6 May 2026 02:57:28 -0700 Subject: [PATCH] CIPLabeler performance: Store vector of bonds (#9250) * CIPLabeler performance: Store vector of bonds CIPLabelling refers to bonds by index over and over again. This causes a measurable hit in performance in findConfigs() because we iterate over a bitset of "allowed" bonds. For very large molecules with many bonds, this can be a rate-limiting step! This affects many PDB-sized structures. 2J3N goes from 0.7s to 0.25s with this change. I had another example for which the findBondWithIdx() call was taking 500ms of a 700ms call (after the performance update in #9171 was implemented) * yikes, XXL reserve thanks, greg Co-authored-by: Greg Landrum --------- Co-authored-by: Greg Landrum --- Code/GraphMol/CIPLabeler/CIPMol.cpp | 9 ++++++--- Code/GraphMol/CIPLabeler/CIPMol.h | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Code/GraphMol/CIPLabeler/CIPMol.cpp b/Code/GraphMol/CIPLabeler/CIPMol.cpp index ed7c1798d..043b65cb1 100644 --- a/Code/GraphMol/CIPLabeler/CIPMol.cpp +++ b/Code/GraphMol/CIPLabeler/CIPMol.cpp @@ -16,7 +16,10 @@ namespace RDKit { namespace CIPLabeler { -CIPMol::CIPMol(ROMol &mol) : d_mol{mol} {} +CIPMol::CIPMol(ROMol &mol) : d_mol{mol} { + d_bonds.reserve(mol.getNumBonds()); + std::ranges::copy(mol.bonds(), std::back_inserter(d_bonds)); +} boost::rational CIPMol::getFractionalAtomicNum(Atom *atom) const { PRECONDITION(atom, "bad atom") @@ -36,7 +39,7 @@ CXXAtomIterator CIPMol::atoms() const { return d_mol.atoms(); } -Bond *CIPMol::getBond(int idx) const { return d_mol.getBondWithIdx(idx); }; +Bond *CIPMol::getBond(int idx) const { return d_bonds[idx]; }; CIPMolSpan CIPMol::getBonds(Atom *atom) const { PRECONDITION(atom, "bad atom") @@ -108,4 +111,4 @@ int CIPMol::getBondOrder(Bond *bond) const { }; } // namespace CIPLabeler -} // namespace RDKit \ No newline at end of file +} // namespace RDKit diff --git a/Code/GraphMol/CIPLabeler/CIPMol.h b/Code/GraphMol/CIPLabeler/CIPMol.h index eda543846..bedd335a2 100644 --- a/Code/GraphMol/CIPLabeler/CIPMol.h +++ b/Code/GraphMol/CIPLabeler/CIPMol.h @@ -97,6 +97,7 @@ class CIPMol { ROMol &d_mol; std::vector d_kekulized_bonds; std::vector> d_atomnums; + std::vector d_bonds; }; } // namespace CIPLabeler