Ludovic Aubry wrote: > On Wed, Feb 26, 2003 at 01:06:44PM -0500, Terry Reedy wrote: >>This suggests a more radical optimization that might do more speedup >>than all the byte-code fiddling currently proposed: automatically >>localize, at definition time, builtins used within a function. This >>would be like giving each function a customized implicit set of >>default args: True=True, None=None, len=len, ...etc. >>If a program alters __builtins__, def statement placement would >>determine which version gets used. >> > > I have a piece of code that does (almost) exactly that, except at > runtime. > It's purpose is to optimize access to globals used as constants by > replacing the LOAD_GLOBAL opcode by a LOAD_CONST. > It does that by creating a new code object for the function you provide > and using a list of symbols to consider constant. > > [code] I suppose this kind of code could be put to some good use if we ever get some of the recently discussed function modifiers into Python: def myFunction(a,b) [bindglobals]: for i in range(len(a)): b[i] = math.sin(a[i]) * math.cos(2) Hmm, now we'd only need a way to describe "this function has no side-effects and behaves like a mathematical function (same inputs map to same outputs)"... then we could also optimize cos(2) into the constants area :-) -- Marc-Andre Lemburg eGenix.com Professional Python Software directly from the Source (#1, Feb 26 2003) >>> Python/Zope Products & Consulting ... http://www.egenix.com/ >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ ________________________________________________________________________ Python UK 2003, Oxford: 34 days left EuroPython 2003, Charleroi, Belgium: 118 days left
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4