[sugar] python imports and performance (was Re: #5549 ...)
Mon Jun 9 12:10:50 EDT 2008
moving to the list as has little to do with the ticket in question.
> Comment(by mstone):
> This seems like a terrible argument to me because of the categorical
> imperative: if everyone blindly followed style guidelines without making a
> conscious assessment of the costs imposed by those guidelines then we'd
> wind up... where we are today, with Python activities that import 10
> seconds worth of code before becoming interactive.
> Thus, while you're correct that we should place a high value on following
> conventions, I happen to think that the 'imports at the top' guideline has
> been so badly discredited by its effect activity startup time as to be
> untenable in the presence of python modules which perform arbitrary
> computation at import time. (We could also decide to refuse to use python
> modules which perform noticeable computation on import, but that seems
> more painful to me. What do you think?)
I don't think that you are on crack, but I think that should explain
better where you want to go ;)
Someone submitted a patch with a violation of the style guidelines.
The submitter commented that this violation was made because of
performance considerations. I explained why there was no performance
hit that would justify that deviance from what is expected the sugar
code to look like. What argument are you calling terrible? What has
Kant to do with all this? Who is blindly following anything?
If activities take X seconds to startup because of module-level code,
it has little to do with the imports being at the top or being inline.
The modules are loaded because they are imported before the activity
window is brought up, and that happens because they are actually
needed to perform all the initializations that we want (perhaps
mistakenly) to do during activity startup.
Now I'm a bit angry at Michael and Chris, because they have managed to
drag me again into this old discussion when a little experimentation
would have convinced them instead. Just try to move the imports from
the top to just before being used, and see if there's any advantage in
Do you really think that I'm so stupid as to have invested so much
work on the prefork hack just to avoid shuffling some imports around?
In fact, I moved one import to inline when I measured that it actually
made a difference (1 second out of 7):
If you can find other modules that are not needed during startup but
are actually slowing activity startup, please send patches. I don't
expect you to have any problem in having them accepted if you show
some evidence of improvements.
And for the record, the right fix from my POV is to only register
names at the module scope, moving all expensive initializations to be
done lazily when things are actually called. Don't know what's the
opinion in the python community about this, though.
More information about the Sugar-devel