-
-
Notifications
You must be signed in to change notification settings - Fork 491
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
sage_wraps should only read the sources of wrapped functions when needed. #11734
Comments
sage_wraps should only read source files when needed. |
comment:1
Attachment: trac11734_sage_wraps_no_sourceread.patch.gz The patch should solve the problem with prematurely reading sources on gentoo. However, I can not test it, myself. Francois, can you verify it? Benefits Startuptime The startuptime did slightly improve (but perhaps that is not significant): Without patch
With patch
Memory The memory consumption improved as well: Without patch:
With patch:
Bugfix Not reading the sources when a function is wrapped has an additional benefit: If one interactively defines a lambda function and wraps it, then the source is not available. Hence, the following example (that is a new doctest) used to fail:
Without the patch, the last line fails with a mysterious attribute error (the user would certainly have not easily been able to track the problem down). |
Changed keywords from sage_wraps sources gentoo to sage_wraps sources gentoo startuptime |
comment:3
I do not fully understand your patch. How does it differ from simply taking out the call to sage_getargspec and moving it into a lambda? (see my attached patch) Btw. On my install of sage-4.7.2alpha2 the doctest described in Bugfix does not fail. |
comment:4
Replying to @saraedum:
If I remember correctly, I once tried that approach. The line Did you run full tests with your patch?
Really? Strange. It failed for me both with sage-4.7.2.alpha1 and with sage-4.6.2. |
comment:5
The tests in sage/misc pass with your patch, and the example from my post above (the "bugfix") works as well. If all tests pass, then you patch should be preferred. It turned out that I am not to blame for the "argspec = sage_getargspec(wrapped)". The first author of #9976 had introduced an alternative approach to provide the argument list when building the documentation -- and I think what we have here is an artefact of that approach. Since it was about documentation: Could you please build the documentation with your patch (I will only be able to do so tomorrow) and look whether the list of arguments of functions and methods created with |
comment:6
PS: Even though the example from my previous post does not fail on your machine (for reasons that I don't understand), it did fail for me. Hence, I think it would make sense to include that example into your patch (you can of course simply copy the example from my patch). |
comment:7
I ran the doctests without long and they passed. Let me try to build the reference manual. |
comment:8
The reference manual seems ok. For example I get complete_primary_decomposition(algorithm='sy') which is a method with the * |
comment:9
I can confirm that the doc tests pass. I can also confirm that your patch provides a similar (small) positive side effect (comparable to what I stated on my patch) on startuptime and memory consumption. Please add the above "bugfix" example to your patch. In the author field, please replace my name by yours. |
This comment has been minimized.
This comment has been minimized.
Changed keywords from sage_wraps sources gentoo startuptime to sage_wraps sources gentoo startuptime sd32 |
comment:11
Hi, I had to take a bit more rest than I expected - exhaustion is bad for you :) I have just tested this patch in 4.7.2.alpha2 and it works. I think Simon has not made clear the fact that my original report was about the sage on gentoo distribution. It still meant that sage was looking at some cython files before starting up, which can't be good for the startup time. |
comment:12
Replying to @kiwifb:
You mean, it would definitely fix the Gentoo problem?
The ticket description states "introduced a problem that makes it impossible start sage-4.7.1 on Gentoo." I thought that it is clear enough.
Yep. Actually I have tested (by inserting print statements in the functions that read the sources for auto-inspection) that no file is read at startup, with the patch. |
comment:13
Concerning documentation: It looks very nice! Just for testing, I had inserted a function with a complicated argument list, and put it under the
It is shown in the reference manual exactly as it should. In addition, the doc tests pass, the startup time seems to slightly improve (perhaps not significantly), and the memory consumption decreases a little. I hope I understood correctly that it will fix the problem on gentoo. In general, if a bug is fixed, it should be demonstrated by a new doc test. The example that I gave above does fail (at least for me) without the patch. So, I think it should be included. If nobody beats me to it, I'd provide that example in a referee patch. Also I don't know the real name of saraedum. So, please insert the name in the Author field. Apart from that, it is a positive review. |
Reviewer: Simon King |
Changed author from Simon King to none |
Author: Julian Rueth |
comment:15
I'm not sure if I misunderstand what you mean to say with 'significantly' but the average startuptime does actually improve with that patch. (I would provide some data but can't reach the machine where that data is stored right now) |
comment:16
Replying to @saraedum:
There is the "sage -startuptime" script. It prints a lot of data, but the time for importing sage.all is most important, as much as I understood. Without the patch, I get with sage-4.7.2.alpha2:
With the patch, I get: Slowest (including children)1.133 sage.all (None) However, these times are a little flaky. So, I don't know if we can call it significant if the difference is 10%. Concerning the additional test: It is a bit strange. It turned out that it does fail when I execute it on command line, but it does not fail (even without your patch) when it is a doc test. Apparently, in a doc test, Sage is able to find the function definition, which is impossible on the command line. |
comment:17
Anyway, I would leave the doctest in; probably we should add a comment, describing this difference. The speedup is actually a little bit mysterious. It occurs once you remove a few sage_wraps decorators. Apparently python's inspect.ArgSpec does something smart once it gets called very often (to speed up things?) which results in a slowdown in our case. |
comment:18
Replying to @saraedum:
OK, please do!
You removed a few sage_wraps for a test? Actually I find the speedup not mysterious. The 10% are just with your patch, i.e., I did not additionally remove sage_wraps. And the reason for the speedup is clear: Python's
and similarly
while the Sage autoinspection finds
In the most difficult cases, |
comment:19
I spend quite a bit of time looking at that speedup yesterday. While everything you say is certainly correct, a big part comes from calling the constructor I mentioned less frequently. It turned out that removing the decorator from any interacts control would almost yield the same speedup - even though the that control is never referenced in the --startuptime call. |
comment:20
Attachment: trac11734_sage_wraps_no_sourceread_lambda.patch.gz With the new patch, all tests pass, and for the reasons mentioned previously it is a positive review. |
This comment has been minimized.
This comment has been minimized.
comment:22
For the patchbot: Apply trac11734_sage_wraps_no_sourceread_lambda.patch |
Merged: sage-4.7.2.alpha3 |
Attachment: trac11734_sage_wraps_no_sourceread_lambda.proper.patch.gz "Proper" Mercurial changeset replacement patch. |
This comment has been minimized.
This comment has been minimized.
comment:24
I've attached a For now, please make sure all your patches start with " I've relaxed that in my version of the merger, but Jeroen and maybe others are likely to use his more restrictive one. |
According to private conversation with Francois Bissey, #9976 has introduced a problem that makes it impossible start sage-4.7.1 on Gentoo. That's pretty serious, and so this ticket is a blocker.
The problem is that sage_wraps reads the sources of to-be-wrapped functions and methods. The sources are stored as an attribute to the wrapper, which, on the one hand, is a waste of memory. Worse: Reading the Cython sources is impossible for sage-on-gentoo. Therefore, sage can't start.
My patch introduces some lightweight classes, that simply store a reference to an object (e.g., the to-be-wrapped function) and return the sources or source lines or the argument list only when called.
Apply only attachment: trac11734_sage_wraps_no_sourceread_lambda.proper.patch to the Sage library.
CC: @kiwifb
Component: misc
Keywords: sage_wraps sources gentoo startuptime sd32
Author: Julian Rueth
Reviewer: Simon King
Merged: sage-4.7.2.alpha3
Issue created by migration from https://trac.sagemath.org/ticket/11734
The text was updated successfully, but these errors were encountered: