-
Notifications
You must be signed in to change notification settings - Fork 53
Speed up "from X import A; from X import B; from X import C; ..." #98
Description
Over in Pyston-land someone remarked that this:
from X import A, B, C, ..., Zis much faster than
from X import A
from X import B
from X import C
.
.
.
from X import ZWe can't easily rewrite the latter as the former, because in edge cases the semantics are different (though maybe Black could take the liberty to do it anyway...?). But we could try to make the latter execute faster -- in theory everything needed is just in sys.modules['X'], though in practice there appear to be some caches that are reset between from X import statements but that are kept around between A, B, ...., Z. Maybe there's some wiggle room or a quicker way to check for cache invalidation (which is probably rare).
Note that X could well be a package path like foo.bar.baz. Also, if X is a package, then A, B, ..., Z could be submodules; but if X is a module, A...Z must be variables (or functions, classes, etc.) defined in X.