[This really is a jython-dev topic, so cross posting there...]

Runtime type observation and inference, along with AST analysis, is useful now, and it's something that any Python implementation can support. This is just a feature of the Python language, and helps make it a dynamic language. I don't know the specifics of the various tools like pylint however. Someone chime in here?

In terms of optimization, Jython gets some support from JIT now, and we expect more in the future. Operators fully inline on Hotspot, and probably on other JVMs too. The new invokedynamic bytecode instruction in Java 7 should enable similar inlining for functions, methods, and other names. (We may even see direct support of this backported to Java 6 JVMs; fingers crossed.)

There are similar opportunities for optimization across the board in Jython. For example, we could readily increase regex and pickle performance by getting rid of the large switch statements and using polymorphic dispatch instead, which should inline much better.

Unfortunately, Python's frame semantics mean that local variables in Python code can and do escape. Their consequent boxing means we pay huge memory allocation costs. Making this go away, along with invokedynamic to make it less contrived, should make possible writing performant inner loops in Python with built-in types, instead of resorting to Java. And so on, such as looking at optimization opportunities for user-defined types, or supporting better unpacking of function calls, or removing frames entirely.

Typing is necessary for some of these optimizations. One possibility is to use the gradual typing scheme, in conjunction with an appropriate surface syntax (I favor decorators). The challenge will be to properly combine this with the dynamic features of Python. Any support should not rule out using metaprogramming. This might be a good topic to discuss at the upcoming summits at PyCon.

Lastly, can any of this typing support be done before 3.x? Sure, since I don't see it as dependent on 3.x specifically. The Jynx project is a good example of what can be done with decorators today for expressing type info to Java.

- Jim

On Tue, Jan 12, 2010 at 10:21 AM, Stefan Behnel <stefan_ml@behnel.de> wrote:
jlist9, 12.01.2010 17:50:
> +1 for type inference. It has been proven to work well in Scala, and
> it's explicit enough.

... except that it won't work as well as in Scala due to language design
differences. But there's a lot you can do without requiring whole program
analysis. Real-world code rarely hits the "general case" where type
inference can't work at all for Python.

Actually, I would expect that the JIT compiler of a hot-spot JVM would do
quite a bit of runtime optimisation for e.g. virtual method calls anyway (I
assume operators are based on that?), so the benefit for Jython should be
smaller than for CPython (or Cython).


This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
Jython-users mailing list

Jim Baker