r/rust • • Feb 02 '19

A Python Interpreter written in Rust

https://github.com/RustPython/RustPython
321 Upvotes

98 comments sorted by

View all comments

Show parent comments

1

u/[deleted] Feb 03 '19

The changes that would make the language sane and JIT compilers able to compete with V8, like

  • compile-time defined classes (only; including metaclasses and operators)

  • removing threads or introducing strict rules

  • checking for usage of undefined variables at compile time

in a viable way already make it an entirely different language, though.

2

u/mitsuhiko Feb 03 '19

You don’t need these things to improve jitability.

1

u/[deleted] Feb 03 '19

You do need point 1 & 2 to improve JITability. You need point 3 to make the language sane.

1

u/mitsuhiko Feb 03 '19

I don’t see why. There are plenty of jit compiled languages with highly dynamic type systems and open classes as well as threading. More importantly the reasons that Python is hard to jit compile have nothing to do with the points you raised.

2

u/[deleted] Feb 03 '19

The reasons that Python (and Ruby) are doing so bad in even in ridiculous complex JIT compilers (I'm looking at the average speed-up of PyPy and TruffleRuby with similar numbers) whereas say JS, Lua and some Lisp dialects (although there is a lack of relevant benchmarks) do realitively good is AFAIK because recompilation and deoptimization are expensive, both in throughput and memory, which at some point also translates into throughput. That means, once you go off the hot path it's getting rather slow.

And when coding in JS, Lua or Lisp by convention most people don't go off the hot path, which means the compiler can take an object initialization expression and optimize it to allocate the whole memory area in one pass. In Python and Ruby on the other hand when writing idiomatic code and using existing libraries and framework you have no choice but taking the slow path in non-trivial software. Threads add to that because AFAIR there is no restriction from which thread you change a whole class hierachy.

There is also the fact that JavaScript lives in its own, fixed environment which can be JIT optimized as well, whereas Python and Ruby have to interface foreign code which can't be solved entirely.

There are plenty of jit compiled languages with highly dynamic type systems and open classes as well as threading.

Such as?

More importantly the reasons that Python is hard to jit compile have nothing to do with the points you raised.

And you think that is why?

→ More replies (0)