Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More effective symbol caching #1859

Closed
FabioLuporini opened this issue Mar 8, 2022 · 1 comment
Closed

More effective symbol caching #1859

FabioLuporini opened this issue Mar 8, 2022 · 1 comment

Comments

@FabioLuporini
Copy link
Contributor

Consider:

from devito import *
from devito.types import _SymbolCache

grid = Grid(shape=(4, 4))

f = Function(name='f', grid=grid)
f0 = Function(name='f', grid=grid)

both f and f0 have the same name, 'f'.
In the _SymbolCache, four entries are created:

 (f, (x, y)): <weakref at 0x14229d880; to 'f' at 0x142284b30>,
 f: <weakref at 0x14229d880; to 'f' at 0x142284b30>,
 (f, (x, y)): <weakref at 0x14229db20; to 'f' at 0x1420ea450>,
 f: <weakref at 0x14229db20; to 'f' at 0x1420ea450>

the f entries represent dynamically allocated classes. This is created by the Python interpreter and will never be freed. It's a tiny amount of bytes per symbol, but if called in a large loop it may cause a non-negligible leak. This appears extremely related to #845.

However, this could be fixable by creating a class f only once, instead of one per new Function. This will require somewhat extending (changing?) the cache_key of the instance Function, which currently is (f, (x, y)), but this is clearly not enough if we were to use a unique class f. Perhaps we could add the id of the object. Maybe the id (or the hash) alone would be enough? if we use the id (hash), it's plausible it's as simple as that -- we don't need f, x, y, etc.

@FabioLuporini
Copy link
Contributor Author

this is fixed now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant