> i am a longtime Reader of this list and this is the first time i a dare to > speak up. > Apology in advance for any noise, silly comments and not posting to > python-ideas ;).
Welcome! > Well how about implementing guards like in pypy? Guards would allow to generate specialized functions without a JIT. Dummy example: def func(arg): arg *= 1 arg += 0 return arg * 16 Can be optimized to: def func(arg): if type(arg) is int: # fast path return arg << 4 else: # slow path arg *= 1 arg += 0 return arg * 16 I prefer a check before executing the code, rather than an exception and reexecute the same code twice. Specializing all functions would waste a lot of memory, so it should only be applied on some very specific cases... It can also be slower if the guard check is slower than the function body! But I bet that guards would help to enable more aggressive optimizations, or at least make some optimizations safe. Dave Malcolm wrote a patch modifying eval.c to support specialized functions. See the http://bugs.python.org/issue10399 I don't know yet what is the best approach for CPython. -- For the specific case of builtin functions and types, I made two changes in Python 3.3: * the type of the builtins mapping can now be any mapping (Python <= 3.2 requires the dict type, dict subtypes are disallowed) * "new" types.MappingProxyType type to create a read-only proxy for a mapping (see also the rejected PEP 416) We may combine these two changes to use a read-only mapping for builtins. It would at least help to ensure that an application does not monkeypatch builtin functions/types. Victor _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com