-
-
Notifications
You must be signed in to change notification settings - Fork 552
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
Do not cache the result of is_Field externally #13370
Comments
comment:1
Timings I made some benchmarks, based on most tests from #11900 and one new test. This is on my laptop, hence the timings differ from the ones that I stated on #11900. sage-5.2.rc0 plus the memleak patches #12969, #715, #12215, #11521, #12313
Here is a new test. First, with "cold" cache:
And now with a "warm" cache:
If one adds the tests from here, one gets:
Hence, no test became slower, but some became clearly faster - in particular the one with echelon form computation. I think an echelon form computation was were Nils noticed the memory leak. Fixing a memory leak I just noticed that I forgot to add the following test to my patch. But anyway, a memory leak has been fixed that hadn't, before:
However, not all is good. There is still another leak left, quite likely due to coercion.
My suggestion is to deal with the remaining leak on a different ticket. But first I need to add one test to my patch... |
Author: Simon King |
comment:2
The doc test is added. I did not run the full test suite yet. But I think I'll already change it into "needs review". |
comment:3
Oops, I think that the new doc test will only work with the other memleak fixes. If this turns out to be correct, I will need to update the dependencies. |
comment:4
I don't know what the patchbot is trying to do. According to the logs, it looks like sage won't even start. But it does for me! Admittedly, I work with a prerelease of 5.2 (not 5.3). |
comment:5
The patch would not apply to sage-5.3.beta2, because of #11310. Since I worked on top of the other memleak fixes, I name them as dependencies as well. |
Work Issues: Cope with import changes in sage/schemes |
comment:6
Too bad. The patch bot is right: The current patch won't work with sage-5.3.beta2, there is an import error at startup. It is in sage/schemes --- again. |
comment:7
The reason is #13089. |
Changed work issues from Cope with import changes in sage/schemes to none |
comment:8
The patch is rebased with respect to #13089. With the stated dependencies on top of sage-5.3.beta2, sage does start. So, I hope that the patchbot can work fine... |
comment:10
The patchbot reports
I do not get that crash, but I do get the error in padic_base_leaves.py. The strange thing is:
but in the doctest the last line returns "False". In other words, there is yet again a case where the absence of a coerce map is cached when this is wrong. I really thought I had fixed that problem in #12969!! |
comment:11
Arrgh, it is even worse! When I take the complete failing test, namely
then every answer is as expected. But when I run the same thing as part of the test suit eof sage.rings.padic_base_leaves, then the last line returns "False". Hence, there is a side effect from another test. And keep in mind that this side-effect results in wrongly caching the absence of a coercion, even though the patch only changes the syntax for detecting fields. |
comment:12
It is worse than worse: According to the patchbot, the problem in padic_base_leaves also occurs with #12313, i.e., before applying #13370. But I do not get that error! Hence: The patchbot finds a wrong coercion cache with #12313, which I only find with #12313. And the patchbot finds a segfault with #12313, that I do not find. |
comment:13
I inserted some lines into sage.structure.parent that print type(S) and id(S) whenever the absence of a coercion gets cached. And I inserted a line into the failing test that prints type and id of the object that fails. It turns out that by the test
in line 478 of sage/rings/padics/padic_base_leaves.py, the absence of a coercion gets cached for an object of type Hence, it seems that the following happens: The absence of a coercion from If this is true, then we have to understand why the callback function of the weak reference to |
comment:14
My hope was that the new fixes in #715 and #12313 ("let the |
comment:46
No segfault this time. I am retrying without #13145. |
comment:47
Is there someone who'd review this? |
comment:48
Needs to be rebased on top of sage-5.7.beta2 |
comment:49
Patch is updated! |
comment:50
I'm all in favour of the idea of the patch. However, the bot seems to indicate there's still some work to do. |
comment:51
Right. Polyhedron seems to be new, so that this rather old patch did not take care of it. |
Attachment: trac13370_deprecate_is_field.patch.gz Deprecate |
comment:52
I have updated the patch, and I hope it'll make the patchbot happy. At least, all tests in sage/geometry pass. Needs review! |
comment:53
Cool stuff! Works for me, so positive review. Note that in [comment:1] you also noted the issue that is now the topic of #14058. |
Reviewer: Nils Bruin |
comment:55
Something that struck me. With the current trick,
is going to be pretty efficient, because the category of R reflects it's a field after the first test. However,
probably isn't efficient (but it probably wasn't before either), because there's no way to register it's NOT a field in its category. I recognize that frequently asking whether a field is indeed a field will happen a lot, whereas frequently confirming something is NOT a field will probably be considerably less common, so perhaps it's not a problem. It does reflect that this solution is accomplishing something quite different from just making |
Merged: sage-5.8.beta0 |
comment:57
Please see #14158 for a blocker follow-up. |
In #11900, a cache has been introduced to sage.rings.ring.is_Field, in order to speed things up. Unfortunately, that caused the following leak:
I think the cleanest solution is:
is_Field(R)
byR in Fields()
Rationale:
is_Field(R) (or _is_Field(R)) will change R.category() into a sub-category of Fields(). But then, the next call to "R in Fields()" will be very fast. Hence, there is no reason (speed-wise) to cache is_Field. Actually,
R in Fields()
should be faster thanis_Field(R)
anyway, because of the cythonisation.Depends on #11310
Depends on #12215
Depends on #11521
Depends on #12313
Depends on #13089
Depends on #12995
CC: @nbruin @jpflori
Component: memleak
Author: Simon King
Reviewer: Nils Bruin
Merged: sage-5.8.beta0
Issue created by migration from https://trac.sagemath.org/ticket/13370
The text was updated successfully, but these errors were encountered: