-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
Garbage Collection #7
Comments
It sounds like this should be pretty straightforward, if |
Implementing this with refcounting would work I suppose. But I think it makes more sense to just let the GC do the work. That's what I did in #9 by making the cache only hold a |
I'm hesitant to ask because I'm not totally sure if/how Julia handles garbage collection of overwritten or deleted methods, but since this is a library for "data as code," I feel the need to clarify: Does it make sense to add a finalizer that deletes the compiled method ( |
A generated function fakes purity and the Julia compiler just slurps it up. So once it's compiled for a dispatch, it won't ever check the generated function again since it'll just use the cached compiled code. This has the weird side effect that if you modify the expression in the dictionary it won't actually update a RuntimeGeneratedFunction, but I think that same process is what makes this safe. |
I'm asking more about what happens to the cached compiled code after generation. If I were to make a really big (like 100MB) expression, when I runtime generate it and call it, that 100MB expression gets saved in the RuntimeGeneratedFunctions.jl cache, but it also gets loaded into the generated function, compiled, turned into Julia IR, LLVM, and eventually assembly. Presumably julia caches at least the assembly somewhere, and it's probably also 100MB or so, right? I'm wondering if we need to delete that as well so we don't leak memory. |
Essentially, I'm concerned that there will be a bunch of specializations of |
I haven't seen that leak in practice at least, and it was a major issue with GeneralizedGenerated that caused the creation of this repo so I assume it's okay? But it's hard to know. |
Memory usage of this simple loop stays static at about 400 MB:
However, the following code explodes the memory usage of Julia 1.5.3:
That said, I'm not sure if it is the intention of this package to avoid such an outcome. |
Digging a bit, no code that Julia compiles is ever garbage collected. |
I understand now I was wrong earlier when I suggested this might be solved by |
It would be good to garbage collect the functions after the handle is lost, since it should essentially be only related to that one object that created it. That would be done by using a finalizer that deletes the function cache from the dictionary. Though that might cause unsafety if someone creates the same function twice. @c42f is there a way to do this safely? The reason we'd want this is because we're looking to build some million like expressions (and chop them up).
The text was updated successfully, but these errors were encountered: