Files
rdkit/Code/GraphMol
Dan Nealschneider 3facd882d6 Speed up GetProp Python keyerrors (#8372)
* Speed up GetProp Python keyerrors

A common pattern _in Python_ for checking for the presence or
absence of a key is:

    try:
       return mol.GetProp('mykey')
    except KeyError:
       return None

Shockingly, this is really slow with boost python objects! I was
recently profiling a workflow and 90% of the time or more was
spent in failed GetProp calls (mostly on bonds, some on atoms
or mols).

I sped up the workflow by protecting the calls using HasProp. But
I think this is a silly trap we've set for our users.

The problem comes because boost::python uses a C++ exception to
indicate that there is already a Python exception set. In C++,
exceptions are slow - they require unrolling a stack. In Python,
exceptions are about the same speed as any other control flow!

This commit speeds up GetProp failures by circumventing the
boost throw_exception_already_set() mechanism.

In my testing, this speeds up failed GetProp substantially:

* Factor of 1000x on Mac
* Factor of 40x on Linux

* Update typed GetXXXProp to bypass boost exceptions

Based on PR #8372

Updates the typed GetIntProp, GetDoubleProp, etc to bypass C++
exceptions in access. This speeds up missing key errors
significantly - for instance, calling mol. GetIntProp with a
missing prop 100,000 times:

Before: 28s
After:  0.05s
2025-04-07 13:55:22 +02:00
..
2025-03-20 07:03:45 -04:00
2025-02-20 05:59:30 +01:00
2019-10-10 20:18:43 +09:00
2025-03-20 07:40:33 +01:00
2025-04-04 15:13:39 +02:00
2025-01-09 07:52:46 +01:00
2023-11-15 06:45:42 +01:00
2025-03-20 07:40:33 +01:00
2019-10-10 20:18:43 +09:00
2025-03-04 14:56:08 +01:00
2025-03-04 14:03:13 +01:00
2025-03-20 07:40:33 +01:00
2025-03-20 07:40:33 +01:00
2025-03-20 07:40:33 +01:00
2023-11-15 06:45:42 +01:00
2018-07-25 09:14:17 +02:00
2025-03-20 07:40:33 +01:00
2022-07-11 11:20:03 +02:00
2025-03-17 19:54:15 +01:00
2021-07-09 15:06:54 +02:00
2025-03-17 19:54:15 +01:00
2018-07-25 09:14:17 +02:00
2019-10-10 20:18:43 +09:00
2020-09-02 04:51:20 +02:00
2023-12-22 04:58:18 +01:00
2019-12-31 06:43:27 +01:00
2024-01-19 18:43:30 +01:00
2024-01-19 18:43:30 +01:00
2023-12-01 05:41:14 +01:00
2024-02-22 06:46:39 +01:00