-
-
Notifications
You must be signed in to change notification settings - Fork 570
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
A coercion-related memory leak #15424
Comments
comment:1
I tried to see where the reference can be coming from:
and I found that with |
comment:2
Replying to @nbruin:
Hm. Is there any global |
comment:3
I just notice: #14711 is still in need of review. I am currently building the branch from there, to see if it fixes the problem from here. |
comment:4
Replying to @simon-king-jena:
No, it does not. |
comment:5
OK, looking at the referrers to the TripleDict I get a sage.structure.coerce.CoercionModel_cache_maps Correction: the values are either So my guess is that this cache is used when determining a common parent and then stores the maps needed to get to that. It seems to me we can mitigate this leak considerably if we DON'T store the maps here if we find a coercion from one into the other would do the job: instead store a symbolic "coerce_to_first" or "coerce_to_second" value in there. In cases where there is a genuine third parent into which we're mapping, it's a little safer: then the codomain at least doesn't keep alive the keys. It's unclear to me how long we should be keeping the common overparent in that case. This cache will mean its life is bounded below by the shortest life time of the two "covered" parents. |
Attachment: chain.png A reference chain preventing an integer mod ring from garbage collection |
comment:6
The attached picture shows that the offending reference chain starts in the module |
comment:7
Indeed, |
comment:8
Ouch. I thought that in our coercion model, maps and actions are cached on the level of parents. Now I see that they additionally are cached in the coercion model! Apparently this additional cache is not always used. For example, it is not used if you just do And then you have a strongly referenced What shall we do about it? Isn't it the case that we are only storing maps that already are cached on the level of parents? Then it would be safe to just store a weak reference to this map, and the problem was solved. |
comment:9
PS: Similarly for |
comment:10
PPS: Which means that we need to make maps weakrefable (actions already are weakrefable). |
Branch: u/SimonKing/ticket/15424 |
Author: Simon King |
Commit: |
comment:12
I did not run the complete doctests, but I have added a new test that shows that I have fixed the problem. It is orthogonal to #14711. As I said above: The idea is to only keep a weak reference from coercion model to coerce maps, which needs to make morphisms weakrefable, and which should be safe because the maps are cached on their dodomain anyway. New commits:
|
Changed keywords from none to coercion model, weak reference |
comment:13
Argh. Schemes seem to hate me. Almost always when I implement something that fixes a problem, it turns out that some examples from sage.schemes will fail, because the elliptic curve code relies on what I intended to fix. But this time it is extreme:
|
Work Issues: Convince elliptic curves to not fail |
comment:15
Don't store weakrefs as values in |
comment:16
Replying to @nbruin:
Oops, I forgot about this.
No. |
comment:17
Replying to @simon-king-jena:
No, this won't work, because there would be no reference back to the pair, and thus it would be immediately garbage collected. |
comment:18
Found it: #14058 seems relevant. Especially read the sage-devel thread referenced there. We've thought quite a bit about this stuff before. Especially with the newly MUCH better lookup performance of |
comment:19
Replying to @nbruin:
OK, then let us see if it fixes the problem. |
comment:20
Yep, #14058 fixes the problem. Then I give a review to this ticket, saying that it is a duplicate and please be resolved as such. |
Changed work issues from Convince elliptic curves to not fail to none |
Changed author from Simon King to none |
Reviewer: Simon King |
Changed branch from u/SimonKing/ticket/15424 to none |
Changed commit from |
Yet another leak (this test is with #15303):
This is astonishing. Wouldn't one think that getting (thus, caching) a coercion or getting an action should trigger a leak, or creating an element? No, we actually need to multiply two elements to find the leak.
Surprising:
Shouldn't there be an action? OK, perhaps not, since coercion is used for the multiplication:
But if coercion is used, then why is establishing a coercion not enough to trigger the leak? In a new session:
CC: @nbruin
Component: memleak
Keywords: coercion model, weak reference
Reviewer: Simon King
Issue created by migration from https://trac.sagemath.org/ticket/15424
The text was updated successfully, but these errors were encountered: