3 ms·
I'm curious, given the presence of a ".pyc", shouldn't these kinds of costs be paid primarily on first invocation "ever"?
by makecheck 9y ago
I'm curious, given the presence of a ".pyc", shouldn't these kinds of costs be paid primarily on first invocation "ever"?
- chronial 9y agoNo, because the string given to eval will not be stored in the pyc – it has to be compiled on every import.
- tankenmate 9y agoIt can't be cached? Is not caching a dependency issue?
- pwdisswordfish 9y agoIt can't, because lol dynamic dispatch. Exercise: what does this code do? import collections collections.namedtuple = lambda _0, _1, _2=False, _3=False: "Where is your god now?" import b b.py: import collections print(collections.namedtuple('Point', ['x', 'y'])) And this is not even particularly 'evil' code, in the sense of relying on internal implementation details; that's just your bread-and-butter Python language semantics. It prevents (or at least complicates) many other potential optimisations as well.
- adambyrtek 9y agoNot in a general case, because eval/exec accepts an arbitrary string which could change at runtime.