-
-
Notifications
You must be signed in to change notification settings - Fork 508
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
Use lazy imports to speed up sage startup time #8254
Comments
comment:1
Could you provide some additional data? Which platforms? I assume that |
comment:2
By "help," I mean "help to identify the problem(s)." |
comment:3
OS X for one. |
comment:4
FWIW, Sage 4.3.3 (with some mods to get it to build on Solaris) takes 8 seconds to start on a Sun Blade 1000, with 2 x 900 MHz CPUs and 2 GB RAM. That machine has 15,000 rpm 2 Gbit/s fibre channel FC-AL disks. Considering the age of that machine, I'm not overly concerned over that one. Although this machine is quite old, the disks are quite high spec. I don't know if that gives any clues. File systems are local. The doc test
takes 459.4 seconds to run on that machine, so this is no quick machine - I had to increase SAGE_TIMEOUT just to get some doctests to pass. Dave |
comment:5
Given the startup time for me, on that SPARC, and the fact I have a quicker SPARC, I'm not overly concerned by this myself. But those interested in fixing it might like to look at using 'iostat', 'vmstat' and 'sar' to see what the system is doing. Dave |
comment:6
PS, that Blade 1000 of mine is using UFS disks, not ZFS. Using ZFS would take more memory from a machine that already has very little. I suspect the startup time has more to do with disk & file-system performance than it does with CPU speed. Dave |
Shaves off about 0.3 seconds for me. Depends on #8456 |
comment:8
Attachment: 8254-lazy-schemes-import.patch.gz I talked to Robert today and he told me thought he had marked this "needs review", but he hadn't. So I am. |
comment:9
Yep, this is ready for review (assuming it hasn't bitrotted). Regarding Davve Kirkby's comment, I agree that disk access is probably the main bottleneck, and this addresses that by loading fewer modules. |
comment:10
The patch applies to 4.6 after rebasing #8456 In my computer, from a first running (disc access is necessary), Sage passes from 12.059 seconds to 11.290 So, a save less than 10% If I further lazy import doing a If I run Sage with the initialitation files in RAM (disc acces is not necessary) the time with lazy_importing all * drops from 1.123 to 0.907 So, still, with lazy imports, disc access is too high. with Robert patch I get the following doctest failures: |
comment:11
The first import * (after every sage -b) needs to import the modules to get the names. However, if there's only a 10% gain, I should take another look and make sure something isn't accidentally still pulling it in. (A lot has changed since I wrote this patch...) |
comment:12
I've attached a patch that seems to get some of the worst offenders for wasteful imports in 4.6. I haven't run doctests yet, though... |
comment:13
From a warm file cache, my patch seems to shave off about 1.4% of the startup time (times averaged over 5 runs). From a cold file cache, my guess is that it would be more than that because the unnecessary imports I take care of touch a lot of files. |
comment:14
Another issue I have found with this patch. With the lazy_imports in all.py, the namespace used in the instances is not the global namespace. (after several runnings of sage, so it uses the cached database of functions)
It does not introduce sloane_sequence function in the global namespace but in sloane_sequence._namespace that seems to not be the global one. |
This comment has been minimized.
This comment has been minimized.
Author: Robert Bradshaw |
comment:15
Okay, I guess because of the ticket title, I attached my patch. But the ticket title is way too general. I've made the title more descriptive, and moved my much simpler patch to #10220 |
comment:16
Concerning the input on the global namespace in sage.all.py one can write
and insert everything in the dictionary G. But his looks like a very ugly hack. |
comment:17
What I wrote above is nonsense. I am adding names to the If we only do lazy_imports from sage.all we will not get an usable enviroment that load fasts. If we add lazy_imports in other all.py files we will get problems messing with namespaces. Suppose the following: in sage.all:[br] in sage.rings.all:[br] If we lazy_import sage.rings.polynomial.all names in sage.rings.all then we have to choose a namespace. If the namespace chosen is the top one. When inserting the real object, it will be inserted in the main namespace, so, in the module sage.rings.all we will always have the lazy_import object. If the namespace chosen is sage.rings.all then we will always have the lazy_object in the main namespace... This is too technical for me to offer a solution at module level. One idea is to add other files called lazy_all.py. these will be modules that import/lazy_import names in the IPython top namespace. They are not intended for the library code, only to have a more fine grain control on what are lazy_importing or not at the start. Comments? It is worth to give it a try? |
comment:18
If we do a lazy_import of x in sage.foo, and then someone does "from sage.foo import x" in m, I don't see any way to resolve the original x in m. It may be worth registering a "top-level" namespace that substitutions would be made into. Note, however, that lazy imports are for library code as well. |
comment:19
I'm making this ticket into a meta-ticket, link from here to various speedups. |
This comment has been minimized.
This comment has been minimized.
Changed keywords from none to sd32 |
comment:26
See https://bugs.python.org/issue34690 for a quite different approach to (significantly) speed up start-up time. It avoids file stats to speed up as well, so I suspect it would be a particularly suitable speed-up for sage (where we're stat-ing loads of files). If we can use this somehow, we'd probably need some tuning parameters to choose which parts of the library are cached and which are loaded fresh. |
Sage still takes too long. 20 seconds, 30 seconds, 5 seconds, on various places... and it is all so painful. This patch attempts to speed up the startup time using lazy imports.
Specific patches at
Component: misc
Keywords: sd32
Author: Robert Bradshaw
Issue created by migration from https://trac.sagemath.org/ticket/8254
The text was updated successfully, but these errors were encountered: