Open mikofski opened 6 years ago
@bmeyers check this out, you can use a unique hash for cells as the keys in a dictionary of cells that are cached. This makes returning memoized cells zeroth order because they are actually stored by their unique hash, and because the same key can't be stored twice, you can never have a duplicate in the cache.
You make the unique hash by appending hex strings of the hash of each value to make a super long string that is unique to a set of parameters, as long as you always append them in the same order.
This is definitely relevant to #48 and is a spinoff of @bmeyers original cache idea in the rejected PR #42 , and a continuation of the accepted PR #43, that closed the relevant issues #34 and #35 about copies, and of course the ability to delay calculation #59.
The idea is simple, every time you make a calculation in
__setattr__
or incalcCells()
:PVcell
, no need to serialize it (the cell) right nowThe cache should be in
pvconstants
and should probably have a limit of 100 or 1000 cells. Any strategy can be used to determine which cells to keep in the cache, for example, a count could be kept of how many times each cell was called, and then the least popular cells are culled as needed.This cache could be repeated for modules and strings as well.
sample code:
This works! Generate two different
PVcells
that are identical, but have different memory locations, and the calculated hash is the same.then in
PVmodules