Speed up parsing by caching Stem.petals
property
Arthur Eigenbrot
Branch: cached_petals
Branch: master
Merged
Merged pull request
Merged in cached_petals (pull request #160)
Stem.petals
propertyMerged in cached_petals (pull request #160)
The
petal
property does an inversion of thekey_to_petal_dict
, which can be (and often is) expensive. Currently we re-do this inversion a lot because thepetal
property (or it’s relative thebud
property) is accessed many times duringupdate_constants
.This PR greatly speeds up parsing by smartly caching the
petals
property. Basically, we know thatpetals
will be identical given identical states ofkey_to_petal_dict
, so we re-generate thepetals
iffkey_to_petal_dict
has been updated since the last time we accessedpetals
.In my rough tests this change speeds up any Parse task by almost a factor of 4 (which makes sense because
stem.bud
was called 4 times inupdate_constants
). Such speed!Â
Additionally, there was some minor cleanup of old logic flow in
ParseDataBase.update_constants
. I’ll leave some comments below where necessary.