Skip to content

Commit 06e09c7

Browse files
authored
cache the results of obj_to_dict to speed up RMSWriter
after calling `obj_to_dict` with a species once, the result is saved in a lookup dictionary so that subsequent calls are 'instant'. This costs memory but for an expensive function like this that inherently ends up calling on the same input a lot, it should be worth it. related comment: #2499 (comment)
1 parent 8e7392e commit 06e09c7

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

rmgpy/yml.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
import os
3636
import yaml
37+
from functools import cache
3738

3839
from rmgpy.chemkin import load_chemkin_file
3940
from rmgpy.species import Species
@@ -104,7 +105,7 @@ def get_radicals(spc):
104105
else:
105106
return spc.molecule[0].multiplicity-1
106107

107-
108+
@cache
108109
def obj_to_dict(obj, spcs, names=None, label="solvent"):
109110
result_dict = dict()
110111
if isinstance(obj, Species):

0 commit comments

Comments
 (0)