Avoid Quartz lazyloader from Quartz import * bug#20
Open
casebeer wants to merge 4 commits intopepijndevos:masterfrom
Open
Avoid Quartz lazyloader from Quartz import * bug#20casebeer wants to merge 4 commits intopepijndevos:masterfrom
from Quartz import * bug#20casebeer wants to merge 4 commits intopepijndevos:masterfrom
Conversation
- Change `from Quartz import *` to the fast `import Quartz`, and update all references to Quartz objects to be explicit. - Add unit test checking import times for pymouse package pyobjc's lazyloader makes the form `from ... import *` very slow. This can make importing pymouse extremely slow on OS X due to its use of from Quartz import *. See the issue discussion on the pyobjc project: https://bitbucket.org/ronaldoussoren/pyobjc/issue/2/faster-metadata-support From that thread on 2013-07-16: > If you are only using framework wrappers: make sure you do not use "from > Foundation import ", use "import Foundation" or "from Foundation import > NSObject" instead. Someone recently noticed that the "from ... import " > form is currently much slower than it used to be, due to the way the > PyObjC lazy loader is implemented. I'm working on a fix for that, but > even with the fix explicit imports will be better because they perform > less form (because explicit imports don't have to resolve the symbols > you don't use). pymouse has this exact problem due to its use of `from Quartz import *`: $ time python -m pymouse ... real 0m16.040s user 0m14.322s sys 0m0.194s Changing to just `import Quartz` solves the extremely long hang at import time problem; after this commit: $ time python -m pymouse ... real 0m0.558s user 0m0.390s sys 0m0.087s
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I've been having a problem with very long import times/hanging on import.
Specifically,
hangs for in excess of 15 seconds on Mac OS X 10.9.3/Python 2.7.5 with pyobjc v2.5.1.
I've traced the issue back to the pyobjc project, which has a bug discussion containing this message:
https://bitbucket.org/ronaldoussoren/pyobjc/issue/2/faster-metadata-support#comment-5204985
The pymouse/mac.py module uses exactly this
from Quartz import *import style.Changing this to
import Quartzand fixing the references to Quartz objects solves the import time issues.I've also added a unit test that checks the import time for pymouse.
Reproducing the bug
Environment
Steps
You should observe at least a 15 second hang with no output or other response. For example:
Results
Before the patch, at version 1.0/b0cc56c:
After changing to
import Quartz:n.b. I've issued substantially this same Pull Request to the PyUserinput project as well.