Skip to content

Commit

Permalink
cache the results of obj_to_dict to speed up RMSWriter
Browse files Browse the repository at this point in the history
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: ReactionMechanismGenerator#2499 (comment)
  • Loading branch information
JacksonBurns authored Jul 27, 2023
1 parent 8e7392e commit 06e09c7
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion rmgpy/yml.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import os
import yaml
from functools import cache

from rmgpy.chemkin import load_chemkin_file
from rmgpy.species import Species
Expand Down Expand Up @@ -104,7 +105,7 @@ def get_radicals(spc):
else:
return spc.molecule[0].multiplicity-1


@cache
def obj_to_dict(obj, spcs, names=None, label="solvent"):
result_dict = dict()
if isinstance(obj, Species):
Expand Down

0 comments on commit 06e09c7

Please sign in to comment.